我正在努力使应用程序与iOS7兼容,而且我遇到了UINavigationBar的问题,这让我发疯了:
我想让我的navigationBar完全透明,没有任何模糊或backgroundPicture,但包含并显示navigationItem按钮。
在iOS6中,我曾经这样做过:
UIImage *maskedImage = [UIImage imageNamed:@"transparent_image.png"]
[navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
但它在iOS7上不再起作用了。
有什么建议吗?
答案 0 :(得分:2)
也许this会回答你的问题?如果您选择视图控制器,然后取消选中“在顶部条下方延伸边缘”旁边的框,则背景图像不会在其下方出血。
答案 1 :(得分:0)
@implementation MyCustomNavigationBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
[self setupBackground];
}
- (void)setupBackground {
self.backgroundColor = [UIColor clearColor];
self.tintColor = [UIColor clearColor];
// make navigation bar overlap the content
self.translucent = YES;
self.opaque = NO;
// remove the default background image by replacing it with a clear image
[self setBackgroundImage:[self.class maskedImage] forBarMetrics:UIBarMetricsDefault];
// remove defualt bottom shadow
[self setShadowImage: [UIImage new]];
}
+ (UIImage *)maskedImage {
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [UIImage imageNamed:@"nav-white-pixel-bg.jpg"];
return [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
}
@end