【发布时间】:2015-08-12 06:05:21
【问题描述】:
我需要使用以下代码创建一个自定义类,以便在 iOS 中为 UINavigationBar 设置阴影。
@interface UINavigationBar (CustomImage)
-(void) applyDefaultStyle;
@end
@implementation UINavigationBar (DropShadow)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"titleBar.png"];
[image drawInRect:CGRectMake(0, 0, 320, 44)];
}
-(void)willMoveToWindow:(UIWindow *)newWindow{
[super willMoveToWindow:newWindow];
[self applyDefaultStyle];
}
- (void)applyDefaultStyle {
// add the drop shadow
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowOffset = CGSizeMake(0.0, 3);
self.layer.shadowOpacity = 0.25;
self.layer.masksToBounds = NO;
self.layer.shouldRasterize = YES;
}@end
我该怎么做?
此外,上面的代码为我的应用程序中的每个导航栏添加了阴影。如何控制这个?我只需要一两个导航栏上的阴影。
【问题讨论】:
标签: ios objective-c uinavigationbar shadow