我希望导航栏的背景颜色为 0.5 alpha,以便能够部分看到下面 View 的内容。我尝试这样做:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.barTintColor = UIColor.blue
self.navigationController?.navigationBar.isTranslucent = true
}
如果我将 isTranslucent
设置为 true
,则 navigationBar
颜色是透明的。如果我将 isTranslucent
设置为 false
,则即使我设置 UIColor.blue.alpha(0.5)
我怎样才能做到这一点?
最佳答案
如果您只想使用 alpha 的 NavigationBar
(不包括状态栏)背景.. 试试这个
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.backgroundColor = UIColor.blue.withAlphaComponent(0.5)
}
如果你想要带有 alpha 的背景颜色,包括状态栏
,恐怕你必须使用带有 alpha 值的图像。 see this
关于ios - 在导航栏中设置带有 alpha 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44125612/