Skip to content

Commit

Permalink
borderless popover
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvise Susmel committed Feb 26, 2013
1 parent 94af1e2 commit 0e01865
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
4 changes: 2 additions & 2 deletions FPPopoverController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
**/
Expand Down
24 changes: 15 additions & 9 deletions FPPopoverController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
1 change: 0 additions & 1 deletion FPPopoverDemo/FPViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
2 changes: 2 additions & 0 deletions FPPopoverView.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef enum FPPopoverArrowDirection: NSUInteger {
#endif

typedef enum {
FPPopoverWhiteTint,
FPPopoverBlackTint,
FPPopoverLightGrayTint,
FPPopoverGreenTint,
Expand All @@ -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;
Expand Down
39 changes: 36 additions & 3 deletions FPPopoverView.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation FPPopoverView
@synthesize relativeOrigin;
@synthesize tint = _tint;
@synthesize draw3dBorder = _draw3dBorder;
@synthesize border = _border;

-(void)dealloc
{
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -180,6 +202,7 @@ -(CGPathRef)newContentPathWithBorderWidth:(CGFloat)borderWidth arrowDirection:(F
CGFloat outside_left = rect.origin.x;



//drawing the border with arrow
CGMutablePathRef path = CGPathCreateMutable();

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Binary file added wiki_images/borderless.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e01865

Please sign in to comment.