如何使 UINavigationBar 透明?虽然我希望它的栏项目保持可见。
最佳答案
如果有人想知道如何在 iOS 7+ 中实现这一点,这里有一个解决方案(也兼容 iOS 6)
在 Objective-C 中
[self.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
在 Swift 3 (iOS 10) 中
self.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.isTranslucent = true
在 Swift 2 中
self.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.translucent = true
在导航栏上将 translucent
设置为 YES
可以解决问题,因为 UINavigationBar
中讨论了一种行为。文档。我将在这里报告相关片段:
If you set this property to
YES
on a navigation bar with an opaque custom background image, the navigation bar will apply a system opacity less than 1.0 to the image.
https://stackoverflow.com/questions/2315862/
相关文章:
objective-c - 实现 API 时如何避免在 block 中捕获 self ?
ios - 突出显示时如何更改 UIButton 的背景颜色?
ios - 从 "bouncing"垂直停止 UIWebView?
ios - 在 Swift 中使用 UI_USER_INTERFACE_IDIOM() 检测当前设备
objective-c - 开始使用 instancetype 而不是 id 会有好处吗?
ios - 卸载应用程序时删除钥匙串(keychain)项目
ios - 设置自定义 UITableViewCells 高度