由于我需要使导航栏透明,一切正常,但现在NavBar项目得到淡出。
如何管理它呢?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationItem.title = "Property Details"
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.bold)]
self.navigationController?.navigationBar.tintColor = UIColor.black
self.navigationController?.navigationBar.alpha = 0.5
}
发布于 2018-05-28 16:10:04
您必须在初始视图控制器上从storyboard添加导航控制器,或者每当您呈现控制器时都必须添加导航控制器。
希望这对你有用
删除alpha = 0.5,对于导航栏透明度,您需要执行以下操作:
// This is color extension to get image from color
public extension UIColor {
func convertImage() -> UIImage {
let rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)
UIGraphicsBeginImageContext(rect.size)
let context: CGContext = UIGraphicsGetCurrentContext()!
context.setFillColor(self.cgColor)
context.fill(rect)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
}
///This is tranceparent image which is get from color
let image = UIColor.init(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.2).convertImage()
self.navigationController?.navigationBar.setBackgroundImage(image, for: .default)
您需要在代码中添加UIColor扩展,然后在控制器中添加底部两行,您可以使用UIColor中的增加或减少alpha来调整淡入淡出的背景视图,现在我已经设置了0.2Alpha
https://stackoverflow.com/questions/50561499
复制相似问题