7

我正在使用以下代码使我的导航栏在 iOS5 中透明:

const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];

升级到 iOS6,导航栏仍然是透明的,但现在它下面有一条细黑线。如何使导航栏完全透明?

我还尝试了以下所有方法:

self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.opaque = YES;
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

提前致谢。

4

3 回答 3

6

解决了。iOS6 为导航栏添加了阴影。所以我在 iOS5 中使用的屏蔽代码仍然可以正常工作 - 我只需要添加

if ([self.navigationController.navigationBar respondsToSelector:@selector(shadowImage)]) 
{ 
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]]; 
} 

摆脱阴影。

于 2012-11-12T09:08:20.187 回答
2
    self.navigationController.navigationBar.translucent = YES; // Setting this slides the view up, underneath the nav bar (otherwise it'll appear black)
    const float colorMask[6] = {222, 255, 222, 255, 222, 255};
    UIImage *img = [[UIImage alloc] init];
    UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];

    [self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
//remove shadow
    [[UINavigationBar appearance] setShadowImage: [[UIImage alloc] init]];
于 2013-05-30T16:22:57.020 回答
1
 if ([self.navigationController.navigationBar respondsToSelector:@selector(shadowImage)])           
 { 
    [self.navigationController.navigationBar setShadowImage:[[[UIImage alloc] init] autorelease]]; 
    // autorelease is necessary, or else [[UIImage alloc] init]'s retainCount is 2.
 }
于 2012-11-19T02:45:39.117 回答