[英]Transparent UINavigationBar
是ios的新手,我發現這個解決方案使UINavigationBar透明化。 在我的項目文件中我可以放置此代碼
[self.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
因此它應用於我正在使用導航控制器的整個項目中。
放入你的rootViewController的viewDidLoad
函數這段代碼:
[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];
if let navigationBar = navigationController?.navigationBar {
navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
navigationBar.shadowImage = UIImage()
navigationBar.translucent = true
navigationController?.view.backgroundColor = .clearColor()
}
if let navigationBar = navigationController?.navigationBar {
navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationBar.shadowImage = UIImage()
navigationBar.isTranslucent = true
navigationController?.view?.backgroundColor = .clear
}
這肯定有用! 透明的UINavigationBar 。
如果你想改變所有應用程序的外觀,我建議你使用它:
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
希望這會有所幫助
在你的UIViewController類中。 您也可以使用UIAppearance機制http://nshipster.com/uiappearance/
放下這個
[[UINavigationBar appearance] setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
[UINavigationBar appearance].shadowImage = [UIImage imageNamed:@"Your image file here"];
成
- ( 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.