当渐变应用于导航栏时,如何更改状态栏的颜色?

时间:2016-12-13 11:30:28

标签: ios swift

我想在导航栏上应用渐变色。我申请了,但状态栏颜色没有变化。任何人都可以帮我这个吗?

以下是实现渐变颜色的代码:

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.

2 个答案:

答案 0 :(得分:3)

使用此:

gradientLayer.frame = CGRect(x:0, y:-20, width:375, height:64)

输出:

enter image description here

在Swift3中:

        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)

使用上面的代码构建后添加了图像

enter image description here