[英]Transparent UINavigationBar in UITableViewController in iOS 8
I have view controllers where I set the navigation bar to be transparent like this: 我在视图控制器中将导航栏设置为透明,如下所示:
viewController.navigationController.navigationBar.translucent = YES;
viewController.edgesForExtendedLayout = UIRectEdgeNone;
[viewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
For my UIViewController
this works fine and I am able to get this: 对于我的
UIViewController
它可以正常工作,并且我可以得到以下信息:
However, when I am using a UITableViewController
it doesn't quite work and I get this: 但是,当我使用
UITableViewController
它不能正常工作,并且得到以下信息:
It't the grey background in the navigation bar that I can't get rid of. 我无法摆脱的不是导航栏中的灰色背景。 I am experiencing this issue in iOS 8.3.
我在iOS 8.3中遇到此问题。 I have tested it in iOS 7.1 and there it works fine.
我已经在iOS 7.1中对其进行了测试,并且可以正常工作。
EDIT: 编辑:
I have tried setting the following without success: 我尝试设置以下内容没有成功:
tableViewController.navigationController.navigationBar.shadowImage = [UIImage new];
tableViewController.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
tableViewController.tableView.backgroundColor = [UIColor clearColor];
There are two ways to do it: 有两种方法可以做到这一点:
1 . 1。 You can override the Navigation Controller class and in the viewDidLoad method of your view controllor just specify this code to change the color of UINavigationBar .
您可以覆盖Navigation Controller类,并且在视图控件的viewDidLoad方法中只需指定此代码即可更改UINavigationBar的颜色。
self.navigationBar.barStyle = UIBarStyle.blue // you can give color of your choice
self.navigationBar.tintColor = UIColor.whiteColor() // or UIColor clearColor
2.If you want to do it universally or want to apply the same color of navigation bar throughout the app then use this below code in AppDelegate's
:didFinishLaunchingWithOptions
method: 2,如果您想普遍使用它,或者想要在整个应用程序中应用相同颜色的导航栏,请在
AppDelegate's
:didFinishLaunchingWithOptions
方法中使用以下代码:
UINavigationBar.appearance() .barTintColor = UIColor(red: 100.0/255.0, green: 226.0/255.0, blue: 98.0/255.0, alpha: 1.0) // you can give color of your choice
UINavigationBar.appearance().tintColor = UIColor.whiteColor() // or UIColor clearColor
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
I believe you need to also set shadowImage
and the background color to clear. 我相信您还需要设置
shadowImage
和背景色以清除。 I use the following and it works fine for iOS7 and iOS8 on all controllers. 我使用以下内容,并且在所有控制器上都适用于iOS7和iOS8。
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f){
self.navigationController.navigationBar.translucent = YES;
}
else{
self.navigationController.navigationBar.translucent = NO;
}
self.navigationController.view.backgroundColor = [UIColor clearColor];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.