![](/img/trans.png)
[英]How to draw a transparent UIToolbar or UINavigationBar in iOS7
[英]How can I make my UINavigationBar totally transparent on iOS7?
我正在开发与iOS7兼容的应用程序,并且遇到UINavigationBar的问题,这使我发疯:
我想使我的navigationBar完全透明,没有任何模糊或backgroundPicture,但包含并显示navigationItem按钮。
在iOS6中,我通常是这样进行的:
UIImage *maskedImage = [UIImage imageNamed:@"transparent_image.png"]
[navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
但它在iOS7上不再起作用。
有什么建议么 ?
也许这会回答您的问题? 如果您选择视图控制器,然后取消选中“在顶部栏下方扩展边缘”旁边的框,则背景图像将不会在其下方流血。
@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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.