透明的UINavigationBar

Nya*_*edy 12 uinavigationcontroller ios

是ios的新手,我发现这个解决方案使UINavigationBar透明化.在我的项目文件中我可以放置此代码

[self.navigationBar setBackgroundImage:[UIImage new]
                     forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
Run Code Online (Sandbox Code Playgroud)

因此它应用于我正在使用导航控制器的整个项目中.

Dim*_*kas 31

输入你viewDidLoad的rootViewController函数这段代码:

Objective-C的:

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                     forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

Swift 2.x:

if let navigationBar = navigationController?.navigationBar {
        navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
        navigationBar.shadowImage = UIImage()
        navigationBar.translucent = true
        navigationController?.view.backgroundColor = .clearColor()
    }
Run Code Online (Sandbox Code Playgroud)

斯威夫特3:

if let navigationBar = navigationController?.navigationBar {
        navigationBar.setBackgroundImage(UIImage(), for: .default)
        navigationBar.shadowImage = UIImage()
        navigationBar.isTranslucent = true
        navigationController?.view?.backgroundColor = .clear
    }
Run Code Online (Sandbox Code Playgroud)

这肯定有用!透明的UINavigationBar.

  • 如果我能再给5个+ 1个,那么我愿意.这是一个很好的解决方案 (3认同)