简体   繁体   English

将UINavigationBar更改为透明颜色

[英]Changing UINavigationBar to transparent color

I want my UINavigationBar to be completely transparent except for the title and the buttons I add to it. 我希望我的UINavigationBar完全透明,除了标题和添加到其中的按钮。

I just can't seem to make it work. 我似乎无法使其工作。 I've tried everything already. 我已经尝试了一切。 This made the most sense to me: 这对我来说最有意义:

override func viewDidLoad() {
    self.title = "CURRENT BALANCE"

    self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController!.navigationBar.shadowImage = UIImage()
    self.navigationController!.navigationBar.isTranslucent = true

    self.setupSideMenu()

    self.topUpButton.asCircle()
    self.exchangeButton.asCircle()
    self.lockButton.asCircle()
}

在此处输入图片说明

this is my OC code to make UINavigationBar to be completely transparent: 这是我的OC代码,使UINavigationBar完全透明:

first set the VC to UINavigationControllerDelegate , then override - (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 首先将VC设置为UINavigationControllerDelegate ,然后覆盖- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

    // change the backgroudcolor black
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.000 green:0.000 blue:0.000 alpha:1.000];
    // change the alpha 0.3
    self.navigationController.navigationBar.alpha = 0.300;
    // change the translucent YES
    self.navigationController.navigationBar.translucent = YES; 

mainwhile, check your code about the self.view.backgroudcolor , if any view under your UINavigationBar have a backgroudcolor, your UINavigationBar will display the view's color. mainwhile,检查你的代码对self.view.backgroudcolor ,如果你在任何视图UINavigationBar有backgroudcolor,你UINavigationBar将显示视图的颜色。

Set background color property of navigation bar 设置导航栏的背景色属性

self.navigationController!.navigationBar.backgroundColor = UIColor.clear

Update: 更新:

self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetricsDefault)

This is transparent NavigationController code for swift 4: 这是Swift 4的透明NavigationController代码:

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationBar.shadowImage = UIImage()
    self.navigationBar.isTranslucent = true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM