导航栏是半透明的,但我想要透明

时间:2015-05-26 22:53:34

标签: ios objective-c

我已按照顶级指南了解如何让我的顶栏透明,但我能得到的最好的是半透明的。我也试图让按钮变白,而不是默认蓝色。我错过了什么?

@implementation FindAssetLocationMapViewController

- (void) viewWillAppear:(BOOL)animated {
    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.extendedLayoutIncludesOpaqueBars = true;
    [self.navigationController.navigationBar setTranslucent:YES];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor redColor];
}

图片如下。我是否应该截取FindAssetLocationMapViewController属性的屏幕截图?为了澄清,导航控制器和导航栏属性没有与之关联的类。

Translucent not Transparent - red for clarity

Nav Controller Attributes

Nav Bar Attributes

1 个答案:

答案 0 :(得分:1)

在您的app委托中尝试此代码,然后删除您拥有的代码:

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0, 0, 1, 1);

    // create a 1 by 1 pixel context
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
    [color setFill];
    UIRectFill(rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

将其放在application:didFinishLaunchingWithOptions:

    //create background images for the navigation bar
    UIImage *clear = [AppDelegate imageWithColor:[UIColor clearColor]];

    //customize the appearance of UINavigationBar
    [[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsCompact];
    [[UINavigationBar appearance] setTranslucent:NO];
    [[UINavigationBar appearance] setShadowImage:[UIImage new]];