我想在导航栏上应用渐变色。我申请了,但状态栏颜色没有变化。任何人都可以帮我这个吗?
以下是实现渐变颜色的代码:
Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.
答案 0 :(得分:3)
使用此:
gradientLayer.frame = CGRect(x:0, y:-20, width:375, height:64)
let colorTop = UIColor(red: 69/255, green: 90/255, blue: 195/255, alpha: 1.0).cgColor
let colorBottom = UIColor(red: 230/255, green: 44/255, blue: 75/255, alpha: 1.0).cgColor
let gradientLayer = CAGradientLayer()
gradientLayer.colors = [ colorTop, colorBottom]
gradientLayer.locations = [ 0.0, 1.0]
gradientLayer.frame = CGRect(x:0, y:-20, width:375, height:64)
self.navigationController?.navigationBar.layer.addSublayer(gradientLayer)
答案 1 :(得分:0)
替换
self.navigationController?.navigationBar.layer.addSublayer(gradientLayer) with
self.navigationController?.navigationBar.layer.sublayers?.insert(gradientLayer, at: 0)
使用上面的代码构建后添加了图像