简体   繁体   English

透明的UINavigationBar

[英]Transparent UINavigationBar

Am newbie to ios and I found this solution on making the UINavigationBar Transparent. 是ios的新手,我发现这个解决方案使UINavigationBar透明化。 Where in my project files can I put this code 在我的项目文件中我可以放置此代码

[self.navigationBar setBackgroundImage:[UIImage new]
                     forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;

So that it is applied in my entire project where navigation controller is being used. 因此它应用于我正在使用导航控制器的整个项目中。

Put in your viewDidLoad function of your rootViewController this code: 放入你的rootViewController的viewDidLoad函数这段代码:

Objective-C: 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];

Swift 2.x: Swift 2.x:

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

Swift 3: 斯威夫特3:

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

This works for sure! 这肯定有用! Transparent UINavigationBar . 透明的UINavigationBar

If you want change the appearance for all your application, I recommend you to use this: 如果你想改变所有应用程序的外观,我建议你使用它:

[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

hope that will help 希望这会有所帮助

In your UIViewController class. 在你的UIViewController类中。 You can also use UIAppearance mechanism http://nshipster.com/uiappearance/ 您也可以使用UIAppearance机制http://nshipster.com/uiappearance/

And place this 放下这个

    [[UINavigationBar appearance] setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
    [UINavigationBar appearance].shadowImage = [UIImage imageNamed:@"Your image file here"];

into

- ( BOOL ) application:( UIApplication* ) application didFinishLaunchingWithOptions:( NSDictionary* ) launchOptions
Transparent UIToolbar:
self.toolbar.setBackgroundImage(UIImage(),
                                forToolbarPosition: UIBarPosition.Any,
                                barMetrics: UIBarMetrics.Default)
self.toolbar.setShadowImage(UIImage(),
                            forToolbarPosition: UIBarPosition.Any)
Transparent UINavigationBar:
self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.translucent = true

设置以下代码

Self.navigationcontroller.navigationbar.transculant=yes;

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

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