Change color of translucent black UINavigationBar

前端 未结 4 1412
后悔当初
后悔当初 2020-12-24 05:45

I stumbled upon this many times, never found a solution. A UINavigationController\'s navigationBar can be set to black translucent like:

self.navigationContr         


        
相关标签:
4条回答
  • 2020-12-24 06:23

    Once you know it, it's fairly simple:

    self.navigationController.navigationBar.tintColor = [UIColor blueColor];
    self.navigationController.navigationBar.alpha = 0.7f;
    self.navigationController.navigationBar.translucent = YES;
    

    The translucent property seems only to determine wether the main view should be visible under the navigation bar, and resizes the view appropiately.

    0 讨论(0)
  • 2020-12-24 06:23

    At least in iOS 6 on an iPhone 4S, you can make a colored translucent navigation bar like this:

    self.navigationController.navigationBar.tintColor = [UIColor blueColor];
    self.navigationController.navigationBar.translucent = YES;
    

    The alpha setting doesn't seem to be necessary anymore. This also leaves my title bright white and my buttons opaque.

    0 讨论(0)
  • 2020-12-24 06:32

    Here is the solution:

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:3.f/255.f green:8.f/255.f blue:61.f/255.f alpha:1]];
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBar.barTintColor = [UINavigationBar appearance].barTintColor;
    
    0 讨论(0)
  • 2020-12-24 06:44

    To mimic more accurately the translucent effect, meaning that only the background of the navbar is translucent, and the buttons, title and everything else are opaque, you can do like this:

    self.navigationController.navigationBar.translucent = YES;
    [(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:0.7f];
    
    0 讨论(0)
提交回复
热议问题