diff --git a/FPPopoverController.h b/FPPopoverController.h index ac39803..7f75959 100644 --- a/FPPopoverController.h +++ b/FPPopoverController.h @@ -49,8 +49,8 @@ /** @brief The tint of the popover. **/ @property(nonatomic,assign) FPPopoverTint tint; -//3d border implementation, thanks Ruben Niculcea -@property(nonatomic,assign) BOOL draw3dBorder; +/** @brief Popover border, default is YES **/ +@property(nonatomic, assign) BOOL border; /** @brief Initialize the popover with the content view controller **/ diff --git a/FPPopoverController.m b/FPPopoverController.m index ba3df93..18369ce 100644 --- a/FPPopoverController.m +++ b/FPPopoverController.m @@ -52,7 +52,7 @@ @implementation FPPopoverController @synthesize origin = _origin; @synthesize arrowDirection = _arrowDirection; @synthesize tint = _tint; -@synthesize draw3dBorder = _draw3dBorder; +@synthesize border = _border; @synthesize alpha = _alpha; -(void)addObservers @@ -112,7 +112,8 @@ -(id)initWithViewController:(UIViewController*)viewController self.alpha = 1.0; self.arrowDirection = FPPopoverArrowDirectionAny; self.view.userInteractionEnabled = YES; - + _border = YES; + _touchView = [[FPTouchView alloc] initWithFrame:self.view.bounds]; _touchView.backgroundColor = [UIColor clearColor]; _touchView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; @@ -215,6 +216,14 @@ -(CGFloat)parentHeight -(void)presentPopoverFromPoint:(CGPoint)fromPoint { self.origin = fromPoint; + + //NO BORDER + if(self.border == NO) + { + _viewController.title = nil; + _viewController.view.clipsToBounds = YES; + } + _contentView.relativeOrigin = [_parentView convertPoint:fromPoint toView:_contentView]; [self.view removeFromSuperview]; @@ -559,15 +568,12 @@ -(void)setShadowsHidden:(BOOL)hidden } #pragma mark 3D Border --(void)setDraw3dBorder:(BOOL)draw3dBorder -{ - _contentView.draw3dBorder = draw3dBorder; - [_contentView setNeedsDisplay]; -} --(BOOL)draw3dBorder +-(void)setBorder:(BOOL)border { - return _contentView.draw3dBorder; + _border = border; + _contentView.border = border; + [_contentView setNeedsDisplay]; } #pragma mark Transparency diff --git a/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate b/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate index af48a46..6508f52 100644 Binary files a/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate and b/FPPopoverDemo.xcodeproj/project.xcworkspace/xcuserdata/alvise.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/FPPopoverDemo/FPViewController.m b/FPPopoverDemo/FPViewController.m index dd86115..9cac520 100644 --- a/FPPopoverDemo/FPViewController.m +++ b/FPPopoverDemo/FPViewController.m @@ -60,7 +60,6 @@ -(IBAction)popover:(id)sender DemoTableController *controller = [[DemoTableController alloc] initWithStyle:UITableViewStylePlain]; controller.delegate = self; popover = [[FPPopoverController alloc] initWithViewController:controller]; - popover.tint = FPPopoverDefaultTint; diff --git a/FPPopoverView.h b/FPPopoverView.h index cf6736c..d3bc5c9 100644 --- a/FPPopoverView.h +++ b/FPPopoverView.h @@ -34,6 +34,7 @@ typedef enum FPPopoverArrowDirection: NSUInteger { #endif typedef enum { + FPPopoverWhiteTint, FPPopoverBlackTint, FPPopoverLightGrayTint, FPPopoverGreenTint, @@ -47,6 +48,7 @@ typedef enum { @property(nonatomic,assign) CGPoint relativeOrigin; @property(nonatomic,assign) FPPopoverTint tint; @property(nonatomic,assign) BOOL draw3dBorder; +@property(nonatomic,assign) BOOL border; //default YES -(void)setArrowDirection:(FPPopoverArrowDirection)arrowDirection; -(FPPopoverArrowDirection)arrowDirection; diff --git a/FPPopoverView.m b/FPPopoverView.m index 5ffc6ea..f3bf62e 100644 --- a/FPPopoverView.m +++ b/FPPopoverView.m @@ -35,6 +35,7 @@ @implementation FPPopoverView @synthesize relativeOrigin; @synthesize tint = _tint; @synthesize draw3dBorder = _draw3dBorder; +@synthesize border = _border; -(void)dealloc { @@ -66,6 +67,9 @@ - (id)initWithFrame:(CGRect)frame //3d border default is on self.draw3dBorder = YES; + //border + self.border = YES; + _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textColor = [UIColor whiteColor]; @@ -102,6 +106,18 @@ -(void)addContentView:(UIView *)contentView [self setupViews]; } +-(void)setBorder:(BOOL)border +{ + _border = border; + //NO BORDER + if(self.border == NO) { + _contentView.clipsToBounds = YES; + self.clipsToBounds = YES; + self.draw3dBorder = NO; + _contentView.layer.cornerRadius = FP_POPOVER_RADIUS; + } +} + #pragma mark drawing //the content with the arrow @@ -114,6 +130,11 @@ -(CGPathRef)newContentPathWithBorderWidth:(CGFloat)borderWidth arrowDirection:(F CGFloat radius = FP_POPOVER_RADIUS; CGFloat b = borderWidth; + //NO BORDER + if(self.border == NO) { + b = 10.0; + } + CGRect rect; if(direction == FPPopoverArrowDirectionUp) { @@ -168,9 +189,10 @@ -(CGPathRef)newContentPathWithBorderWidth:(CGFloat)borderWidth arrowDirection:(F else if (ay +2*aw + 2*b > self.bounds.size.height) ay = self.bounds.size.height - 2*aw - 2*b; + //ROUNDED RECT // arrow UP - CGRect innerRect = CGRectInset(rect, radius, radius); + CGRect innerRect = CGRectInset(rect, radius, radius); CGFloat inside_right = innerRect.origin.x + innerRect.size.width; CGFloat outside_right = rect.origin.x + rect.size.width; CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height; @@ -180,6 +202,7 @@ -(CGPathRef)newContentPathWithBorderWidth:(CGFloat)borderWidth arrowDirection:(F CGFloat outside_left = rect.origin.x; + //drawing the border with arrow CGMutablePathRef path = CGPathCreateMutable(); @@ -312,7 +335,12 @@ -(CGGradientRef)newGradient colors[3] = colors[7] = 1.0; } } - + else if(self.tint == FPPopoverWhiteTint) + { + colors[0] = colors[1] = colors[2] = 1.0; + colors[0] = colors[1] = colors[2] = 1.0; + colors[3] = colors[7] = 1.0; + } CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, NULL, 2); @@ -337,7 +365,8 @@ - (void)drawRect:(CGRect)rect //content fill CGPathRef contentPath = [self newContentPathWithBorderWidth:2.0 arrowDirection:_arrowDirection]; - CGContextAddPath(ctx, contentPath); + + CGContextAddPath(ctx, contentPath); CGContextClip(ctx); // Draw a linear gradient from top to bottom @@ -376,6 +405,10 @@ - (void)drawRect:(CGRect)rect { CGContextSetRGBFillColor(ctx, 0.18, 0.30, 0.03, 1.0); } + else if(self.tint == FPPopoverWhiteTint) + { + CGContextSetRGBFillColor(ctx, 1, 1, 1, 1.0); + } CGContextFillRect(ctx, CGRectMake(0, end.y, self.bounds.size.width, self.bounds.size.height-end.y)); diff --git a/wiki_images/borderless.png b/wiki_images/borderless.png new file mode 100644 index 0000000..b3cd4ad Binary files /dev/null and b/wiki_images/borderless.png differ