Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FPPopoverView.m #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 96 additions & 38 deletions FPPopoverView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,70 @@
#define FP_POPOVER_ARROW_HEIGHT 20.0
#define FP_POPOVER_ARROW_BASE 20.0
#define FP_POPOVER_RADIUS 10.0
#define FP_MARGIN 10.0

@interface UIView (CustomView)

@property(nonatomic, assign) CGFloat left;
@property(nonatomic, assign) CGFloat top;
@property(nonatomic, assign, readonly) CGFloat right;
@property(nonatomic, assign, readonly) CGFloat bottom;
@property(nonatomic, assign) CGFloat width;
@property(nonatomic, assign) CGFloat height;

@end

@implementation UIView (CustomView)

- (CGFloat)left {
return self.frame.origin.x;
}

- (void)setLeft:(CGFloat)x {
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}

- (CGFloat)top {
return self.frame.origin.y;
}

- (void)setTop:(CGFloat)y {
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}

- (CGFloat)right {
return self.frame.origin.x + self.frame.size.width;
}

- (CGFloat)bottom {
return self.frame.origin.y + self.frame.size.height;
}

- (CGFloat)width {
return self.frame.size.width;
}

- (void)setWidth:(CGFloat)width {
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}

- (CGFloat)height {
return self.frame.size.height;
}

- (void)setHeight:(CGFloat)height {
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}

@end

//iVars
@interface FPPopoverView()
Expand Down Expand Up @@ -456,59 +520,53 @@ -(void)setupViews

if(_arrowDirection == FPPopoverArrowDirectionUp)
{
contentRect.origin = CGPointMake(10, 60);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-70);
_titleLabel.frame = CGRectMake(10, 30, self.bounds.size.width-20, 20);
if (self.title==nil || self.title.length==0) {
contentRect.origin = CGPointMake(10, 30);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-40);
}
if (self.title == nil || self.title.length == 0)
_titleLabel.frame = CGRectMake(FP_MARGIN, FP_POPOVER_ARROW_HEIGHT, self.width - FP_MARGIN * 2, 0);
else
_titleLabel.frame = CGRectMake(FP_MARGIN, FP_MARGIN + FP_POPOVER_ARROW_HEIGHT, self.width - FP_MARGIN * 2, 20);
contentRect.origin = CGPointMake(FP_MARGIN, _titleLabel.bottom + FP_MARGIN);
contentRect.size = CGSizeMake(self.width - FP_MARGIN * 2, self.height - contentRect.origin.y - FP_MARGIN);
}
else if(_arrowDirection == FPPopoverArrowDirectionDown)
{
contentRect.origin = CGPointMake(10, 40);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-70);
_titleLabel.frame = CGRectMake(10, 10, self.bounds.size.width-20, 20);
if (self.title==nil || self.title.length==0) {
contentRect.origin = CGPointMake(10, 10);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-40);
}
if (self.title == nil || self.title.length == 0)
_titleLabel.frame = CGRectMake(FP_MARGIN, 0, self.width - FP_MARGIN * 2, 0);
else
_titleLabel.frame = CGRectMake(FP_MARGIN, FP_MARGIN, self.width - FP_MARGIN * 2, 20);
contentRect.origin = CGPointMake(FP_MARGIN, _titleLabel.bottom + FP_MARGIN);
contentRect.size = CGSizeMake(self.width - FP_MARGIN * 2, self.height - contentRect.origin.y - FP_MARGIN - FP_POPOVER_ARROW_HEIGHT);
}


else if(_arrowDirection == FPPopoverArrowDirectionRight)
{
contentRect.origin = CGPointMake(10, 40);
contentRect.size = CGSizeMake(self.bounds.size.width-40, self.bounds.size.height-50);
_titleLabel.frame = CGRectMake(10, 10, self.bounds.size.width-20, 20);
if (self.title==nil || self.title.length==0) {
contentRect.origin = CGPointMake(10, 10);
contentRect.size = CGSizeMake(self.bounds.size.width-40, self.bounds.size.height-20);
}
if (self.title == nil || self.title.length == 0)
_titleLabel.frame = CGRectMake(FP_MARGIN, 0, self.width - FP_MARGIN * 2, 0);
else
_titleLabel.frame = CGRectMake(FP_MARGIN, FP_MARGIN, self.width - FP_MARGIN * 2 - FP_POPOVER_ARROW_HEIGHT, 20);
contentRect.origin = CGPointMake(FP_MARGIN, _titleLabel.bottom + FP_MARGIN);
contentRect.size = CGSizeMake(self.width - FP_MARGIN * 2 - FP_POPOVER_ARROW_HEIGHT, self.height - contentRect.origin.y - FP_MARGIN);
}

else if(_arrowDirection == FPPopoverArrowDirectionLeft)
{
contentRect.origin = CGPointMake(10 + FP_POPOVER_ARROW_HEIGHT, 40);
contentRect.size = CGSizeMake(self.bounds.size.width-40, self.bounds.size.height-50);
_titleLabel.frame = CGRectMake(10, 10, self.bounds.size.width-20, 20);
if (self.title==nil || self.title.length==0) {
contentRect.origin = CGPointMake(10+ FP_POPOVER_ARROW_HEIGHT, 10);
contentRect.size = CGSizeMake(self.bounds.size.width-40, self.bounds.size.height-20);
}
if (self.title == nil || self.title.length == 0)
_titleLabel.frame = CGRectMake(FP_MARGIN + FP_POPOVER_ARROW_HEIGHT, 0, self.width - FP_MARGIN * 2, 0);
else
_titleLabel.frame = CGRectMake(FP_MARGIN + FP_POPOVER_ARROW_HEIGHT, FP_MARGIN, self.width - FP_MARGIN * 2 - FP_POPOVER_ARROW_HEIGHT, 20);
contentRect.origin = CGPointMake(FP_MARGIN + FP_POPOVER_ARROW_HEIGHT, _titleLabel.bottom + FP_MARGIN);
contentRect.size = CGSizeMake(self.width - FP_MARGIN * 2 - FP_POPOVER_ARROW_HEIGHT, self.height - contentRect.origin.y - FP_MARGIN);
}

else if(_arrowDirection == FPPopoverNoArrow)
{
contentRect.origin = CGPointMake(10, 40);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-50);
_titleLabel.frame = CGRectMake(10, 10, self.bounds.size.width-20, 20);
if (self.title==nil || self.title.length==0) {
contentRect.origin = CGPointMake(10, 30);
contentRect.size = CGSizeMake(self.bounds.size.width-20, self.bounds.size.height-40);
}
if (self.title == nil || self.title.length == 0)
_titleLabel.frame = CGRectMake(FP_MARGIN, 0, self.width - FP_MARGIN * 2, 0);
else
_titleLabel.frame = CGRectMake(FP_MARGIN, FP_MARGIN, self.width - FP_MARGIN * 2, 20);
contentRect.origin = CGPointMake(FP_MARGIN, _titleLabel.bottom + FP_MARGIN);
contentRect.size = CGSizeMake(self.width - FP_MARGIN * 2, self.height - contentRect.origin.y - FP_MARGIN);
}

_contentView.frame = contentRect;
_titleLabel.text = self.title;

Expand Down