答案 0 :(得分:1)
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = UIColor.clear
答案 1 :(得分:0)
您还可以尝试以下代码。
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default);
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
self.navigationController?.navigationBar.isTranslucent = true
答案 2 :(得分:0)
self.navigationController?.navigationBar.setBackgroundImage(imageWithColor(color: color.withAlphaComponent(alpha)), for: .default)
self.navigationController?.navigationBar.shadowImage = imageWithColor(color: color.withAlphaComponent(alpha))
fileprivate func imageWithColor(color : UIColor) -> UIImage? {
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext(rect.size)
let ctx = UIGraphicsGetCurrentContext()
ctx?.setFillColor(color.cgColor)
ctx?.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
拨打func viewWillAppera
。你会得到