0
嘿,我正在尝试向我的项目中的所有UINavigationBars添加阴影。我已经尝试过在本网站和其他互联网教程中推荐的一些东西,但没有得到一个阴影坚持下去的运气。我试图把它使用我在Photoshop中创建一个阴影图像,并呼吁在主要的appDelegate如下:IOS:无法将阴影添加到UINavigationBar
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"shadowTest.png"]];
我已经出子类的UINavigationBar的,并试图将财产从内部类中的分配awakeFromNib
方法仍然没有。然后我尝试用<QuartzCore/QuartzCore.h>
图像框架手动创建阴影,但没有发生任何事情。我使用子类来覆盖drawRect
方法,这是否会导致我的问题?这是UINavigationBar类,我最近尝试让阴影保持不变。
#import "BasicNavigationBar.h"
@implementation BasicNavigationBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
// draw shadow
self.layer.masksToBounds = NO;
self.layer.shadowOffset = CGSizeMake(0, 3);
self.layer.shadowOpacity = 1.0;
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, rect);
}
@end
这会解释很多。我可以将背景图像设置为平坦白色,完全忘记子类别,然后在主代表中添加阴影图像? – ScottOBot
@ScottOBot没错。 – Sulthan