11/*
2- Version 0.1.2
2+ Version 0.1.3
33
44 WYPopoverController is available under the MIT license.
55
@@ -157,8 +157,8 @@ + (UIImage *)imageWithColor:(UIColor *)color
157157 UIGraphicsBeginImageContextWithOptions (rect.size , NO , 0 .0f );
158158 [color setFill ];
159159 [roundedRect fill ];
160- [roundedRect stroke ];
161- [roundedRect addClip ];
160+ // [roundedRect stroke];
161+ // [roundedRect addClip];
162162 UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
163163 UIGraphicsEndImageContext ();
164164 return [image resizableImageWithCapInsets: UIEdgeInsetsMake (cornerRadius, cornerRadius, cornerRadius, cornerRadius)];
@@ -343,7 +343,7 @@ - (void)drawRect:(CGRect)rect
343343 }
344344 CGContextRestoreGState (context);
345345 }
346-
346+
347347 CGContextSaveGState (context);
348348 {
349349 if (wantsDefaultContentAppearance == NO )
@@ -475,6 +475,8 @@ @interface WYPopoverBackgroundView ()
475475@property (nonatomic , assign ) CGFloat arrowOffset;
476476@property (nonatomic , assign ) BOOL wantsDefaultContentAppearance;
477477
478+ @property (nonatomic , strong , readonly ) UIColor* defaultTintColor;
479+
478480- (void )setViewController : (UIViewController*)viewController ;
479481
480482- (CGRect)outerRect ;
@@ -525,32 +527,61 @@ @implementation WYPopoverBackgroundView
525527@synthesize arrowOffset;
526528@synthesize navigationBarHeight;
527529@synthesize wantsDefaultContentAppearance;
530+ @synthesize defaultTintColor;
531+
528532@synthesize outerShadowInsets;
529533
530534+ (void )load
531535{
532536 @autoreleasepool {
533537 WYPopoverBackgroundView* appearance = [WYPopoverBackgroundView appearance ];
534- appearance.tintColor = nil ;
535- appearance.strokeColor = nil ;
536- appearance.fillTopColor = nil ;
537- appearance.fillBottomColor = nil ;
538- appearance.glossShadowColor = nil ;
539- appearance.glossShadowOffset = CGSizeMake (0 , 1.5 );
540- appearance.glossShadowBlurRadius = 0 ;
541- appearance.borderWidth = 6 ;
542- appearance.arrowBase = 42 ;
543- appearance.arrowHeight = 18 ;
544- appearance.outerShadowColor = [UIColor colorWithWhite: 0 alpha: 0.75 ];
545- appearance.outerShadowBlurRadius = 8 ;
546- appearance.outerShadowOffset = CGSizeMake (0 , 2 );
547- appearance.outerCornerRadius = 8 ;
548- appearance.minOuterCornerRadius = 0 ;
549- appearance.innerShadowColor = [UIColor colorWithWhite: 0 alpha: 0.75 ];
550- appearance.innerShadowBlurRadius = 2 ;
551- appearance.innerShadowOffset = CGSizeMake (0 , 1 );
552- appearance.innerCornerRadius = 6 ;
553- appearance.viewContentInsets = UIEdgeInsetsMake (3 , 0 , 0 , 0 );
538+
539+ if (WYPOPOVER_IS_IOS_LESS_THAN (@" 7.0" ))
540+ {
541+ appearance.tintColor = nil ;
542+ appearance.strokeColor = nil ;
543+ appearance.fillTopColor = nil ;
544+ appearance.fillBottomColor = nil ;
545+ appearance.glossShadowColor = nil ;
546+ appearance.glossShadowOffset = CGSizeMake (0 , 1.5 );
547+ appearance.glossShadowBlurRadius = 0 ;
548+ appearance.borderWidth = 6 ;
549+ appearance.arrowBase = 42 ;
550+ appearance.arrowHeight = 18 ;
551+ appearance.outerShadowColor = [UIColor colorWithWhite: 0 alpha: 0.75 ];
552+ appearance.outerShadowBlurRadius = 8 ;
553+ appearance.outerShadowOffset = CGSizeMake (0 , 2 );
554+ appearance.outerCornerRadius = 8 ;
555+ appearance.minOuterCornerRadius = 0 ;
556+ appearance.innerShadowColor = [UIColor colorWithWhite: 0 alpha: 0.75 ];
557+ appearance.innerShadowBlurRadius = 2 ;
558+ appearance.innerShadowOffset = CGSizeMake (0 , 1 );
559+ appearance.innerCornerRadius = 6 ;
560+ appearance.viewContentInsets = UIEdgeInsetsMake (3 , 0 , 0 , 0 );
561+ }
562+ else
563+ {
564+ appearance.tintColor = nil ;
565+ appearance.strokeColor = [UIColor clearColor ];
566+ appearance.fillTopColor = nil ;
567+ appearance.fillBottomColor = nil ;
568+ appearance.glossShadowColor = nil ;
569+ appearance.glossShadowOffset = CGSizeZero;
570+ appearance.glossShadowBlurRadius = 0 ;
571+ appearance.borderWidth = 0 ;
572+ appearance.arrowBase = 25 ;
573+ appearance.arrowHeight = 13 ;
574+ appearance.outerShadowColor = [UIColor clearColor ];
575+ appearance.outerShadowBlurRadius = 0 ;
576+ appearance.outerShadowOffset = CGSizeZero;
577+ appearance.outerCornerRadius = 8 ;
578+ appearance.minOuterCornerRadius = 0 ;
579+ appearance.innerShadowColor = [UIColor clearColor ];
580+ appearance.innerShadowBlurRadius = 0 ;
581+ appearance.innerShadowOffset = CGSizeZero;
582+ appearance.innerCornerRadius = 0 ;
583+ appearance.viewContentInsets = UIEdgeInsetsMake (3 , 0 , 0 , 0 );
584+ }
554585 }
555586}
556587
@@ -774,7 +805,7 @@ - (UIColor*)fillTopColor
774805
775806 if (baseColor == nil )
776807 {
777- baseColor = WYPOPOVER_DEFAULT_TINT_COLOR ;
808+ baseColor = self. defaultTintColor ;
778809 }
779810
780811 result = baseColor;
@@ -789,12 +820,24 @@ - (UIColor*)fillBottomColor
789820
790821 if (result == nil )
791822 {
792- result = [self .fillTopColor colorByDarken: 0.4 ];
823+ result = ( WYPOPOVER_IS_IOS_LESS_THAN ( @" 7.0 " )) ? [self .fillTopColor colorByDarken: 0.4 ] : self. fillTopColor ;
793824 }
794825
795826 return result;
796827}
797828
829+ - (UIColor*)defaultTintColor
830+ {
831+ BOOL isUI7 = (WYPOPOVER_IS_IOS_LESS_THAN (@" 7.0" ) == NO );
832+
833+ CGFloat r = ((isUI7) ? 244 . : 55 .) / 255 .;
834+ CGFloat g = ((isUI7) ? 244 . : 63 .) / 255 .;
835+ CGFloat b = ((isUI7) ? 244 . : 71 .) / 255 .;
836+
837+ UIColor* result = [UIColor colorWithRed: r green: g blue: b alpha: 1 ];
838+ return result;
839+ }
840+
798841#pragma mark Drawing
799842
800843- (void )setNeedsDisplay
@@ -1165,6 +1208,8 @@ @interface WYPopoverController () <WYPopoverOverlayViewDelegate>
11651208@property (nonatomic , strong , readonly ) UIView *rootView;
11661209@property (nonatomic , assign , readonly ) CGRect rootViewFrame;
11671210
1211+ @property (nonatomic , strong , readonly ) UIColor* overlayColor;
1212+
11681213- (void )dismissPopoverAnimated : (BOOL )animated callDelegate : (BOOL )callDelegate ;
11691214
11701215- (WYPopoverArrowDirection)arrowDirectionForRect : (CGRect)aRect
@@ -1257,6 +1302,12 @@ - (CGRect)rootViewFrame
12571302 return result;
12581303}
12591304
1305+ - (UIColor *)overlayColor
1306+ {
1307+ UIColor* result = (WYPOPOVER_IS_IOS_LESS_THAN (@" 7.0" )) ? [UIColor clearColor ] : [UIColor colorWithWhite: 0 alpha: 0.15 ];
1308+ return result;
1309+ }
1310+
12601311- (void )presentPopoverFromRect : (CGRect)aRect inView : (UIView *)aView permittedArrowDirections : (WYPopoverArrowDirection)arrowDirections animated : (BOOL )aAnimated
12611312{
12621313 NSAssert ((arrowDirections != WYPopoverArrowDirectionUnknown), @"WYPopoverArrowDirection must not be UNKNOWN");
@@ -1274,7 +1325,7 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr
12741325 overlayView = [[WYPopoverOverlayView alloc ] initWithFrame: rootViewFrame];
12751326 overlayView.autoresizesSubviews = NO ;
12761327 overlayView.userInteractionEnabled = YES ;
1277- overlayView.backgroundColor = WYPOPOVER_DEFAULT_OVERLAY_COLOR ;
1328+ overlayView.backgroundColor = self. overlayColor ;
12781329 overlayView.delegate = self;
12791330 overlayView.passthroughViews = passthroughViews;
12801331
@@ -1315,16 +1366,7 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr
13151366
13161367 [self positionPopover ];
13171368
1318- // default content appearance ?
1319- if (wantsDefaultContentAppearance == NO )
1320- {
1321- if ([viewController isKindOfClass: [UINavigationController class ]])
1322- {
1323- [((UINavigationController*)viewController).navigationBar setBackgroundImage: [UIImage imageWithColor: [UIColor clearColor ]] forBarMetrics: UIBarMetricsDefault];
1324-
1325- [((UINavigationController*)viewController).navigationBar setBackgroundImage: [UIImage imageWithColor: [UIColor clearColor ]] forBarMetrics: UIBarMetricsLandscapePhone];
1326- }
1327- }
1369+ [self drawPopoverNavigationBar ];
13281370
13291371 containerView.hidden = NO ;
13301372
@@ -1377,6 +1419,76 @@ - (void)presentPopoverFromRect:(CGRect)aRect inView:(UIView *)aView permittedArr
13771419 }
13781420}
13791421
1422+ - (void )drawPopoverNavigationBar
1423+ {
1424+ if (wantsDefaultContentAppearance == NO )
1425+ {
1426+ if ([viewController isKindOfClass: [UINavigationController class ]])
1427+ {
1428+ UINavigationController* navigationController = (UINavigationController *)viewController;
1429+
1430+ CGFloat navigationBarHeight = navigationController.navigationBar .bounds .size .height ;
1431+
1432+ UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect: CGRectMake (0 , 0 , 10 , navigationBarHeight)];
1433+
1434+ UIGraphicsBeginImageContextWithOptions (rectPath.bounds .size , NO , 0 .0f );
1435+
1436+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB ();
1437+ CGContextRef context = UIGraphicsGetCurrentContext ();
1438+
1439+ // // Gradient Declarations
1440+ NSArray * fillGradientColors = [NSArray arrayWithObjects:
1441+ (id )containerView.fillTopColor.CGColor,
1442+ (id )containerView.fillBottomColor.CGColor,
1443+ nil ];
1444+
1445+ CGFloat fillGradientLocations[] = {0 , 1 };
1446+
1447+ CGGradientRef fillGradient = CGGradientCreateWithColors (colorSpace, (__bridge CFArrayRef)fillGradientColors, fillGradientLocations);
1448+
1449+ // // Drawing
1450+ CGContextSaveGState (context);
1451+ {
1452+ // CGContextAddPath(context, [rectPath CGPath]);
1453+ // CGContextClip(context);
1454+
1455+ [rectPath addClip ];
1456+
1457+ CGFloat gradientTopPosition = [containerView innerRect ].origin .y - navigationBarHeight + containerView.outerShadowInsets .top ;
1458+ CGFloat gradientBottomPosition = gradientTopPosition + [containerView outerRect ].size .height ;
1459+
1460+ // NSLog(@"top = %f, bottom = %f", gradientTopPosition, gradientBottomPosition);
1461+
1462+ CGContextDrawLinearGradient (context, fillGradient,
1463+ CGPointMake (0 , gradientTopPosition),
1464+ CGPointMake (0 , gradientBottomPosition),
1465+ 0 );
1466+ }
1467+ CGContextRestoreGState (context);
1468+
1469+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext ();
1470+ UIGraphicsEndImageContext ();
1471+
1472+ CGGradientRelease (fillGradient);
1473+ CGColorSpaceRelease (colorSpace);
1474+
1475+ // NSLog(@"image.size = %@", NSStringFromCGSize(image.size));
1476+
1477+
1478+ // image = [image resizableImageWithCapInsets:UIEdgeInsetsZero];
1479+
1480+ [navigationController.navigationBar setBackgroundImage: image forBarMetrics: UIBarMetricsDefault];
1481+ [navigationController.navigationBar setBackgroundImage: image forBarMetrics: UIBarMetricsLandscapePhone];
1482+
1483+ if (containerView.borderWidth == 0 )
1484+ {
1485+ viewController.view .clipsToBounds = YES ;
1486+ viewController.view .layer .cornerRadius = containerView.outerCornerRadius ;
1487+ }
1488+ }
1489+ }
1490+ }
1491+
13801492- (void )presentPopoverFromBarButtonItem : (UIBarButtonItem *)item permittedArrowDirections : (WYPopoverArrowDirection)arrowDirections animated : (BOOL )aAnimated
13811493{
13821494 barButtonItem = item;
0 commit comments