IOS 在导航条的下方加上阴影

来源:互联网 发布:js的执行原理 编辑:程序博客网 时间:2024/06/13 21:11

工程需要包含 QuartzCore.Framework。

////  UINavigationBar+JTDropShadow.h////  Created by james on 9/20/11.//  http://ioscodesnippet.tumblr.com//  #import @interface UINavigationBar (JTDropShadow) - (void)dropShadowWithOffset:(CGSize)offset                      radius:(CGFloat)radius                       color:(UIColor *)color                     opacity:(CGFloat)opacity;  @end    ////  UINavigationBar+JTDropShadow.m////  Created by james on 9/20/11.//  http://ioscodesnippet.tumblr.com//  #import "UINavigationBar+JTDropShadow.h" #import   @implementation UINavigationBar (JTDropShadow) - (void)dropShadowWithOffset:(CGSize)offset                      radius:(CGFloat)radius                       color:(UIColor *)color                     opacity:(CGFloat)opacity {     // Creating shadow path for better performance    CGMutablePathRef path = CGPathCreateMutable();    CGPathAddRect(path, NULL, self.bounds);    self.layer.shadowPath = path;    CGPathCloseSubpath(path);    CGPathRelease(path);     self.layer.shadowColor = color.CGColor;    self.layer.shadowOffset = offset;    self.layer.shadowRadius = radius;    self.layer.shadowOpacity = opacity;     // Default clipsToBounds is YES, will clip off the shadow, so we disable it.    self.clipsToBounds = NO; } @end  //用法如下 - (void)viewDidLoad {    [super viewDidLoad];    ...    [self.navigationController.navigationBar dropShadowWithOffset:CGSizeMake(0, 3)                                                           radius:1                                                            color:[UIColor darkGrayColor]                                                          opacity:1];    ...}


原创粉丝点击