2017-09-11 54 views
0

我想设置我的背景颜色全屏(也包括导航栏和状态栏)与渐变颜色。现在,我通过创建梯度在导航控制器内的UIViewController中设置背景

func setDefaultColorBackground() { 
    let colorTop = UIColor(hexString: "804b8a").cgColor 
    let colorBottom = UIColor(hexString: "42074b").cgColor 

    let gradientLayer = CAGradientLayer() 
    gradientLayer.colors = [ colorTop, colorBottom] 
    gradientLayer.locations = [ 0.0, 1.0] 
    gradientLayer.frame = self.view.bounds 

    self.view.layer.insertSublayer(gradientLayer, at: 0) 
} 

所以我在ViewController在我view添加层制造这一点。它的工作原理,但它并没有掩盖状态栏和导航栏。看到这个图像: background

我觉得背景只填充导航栏下的视图。无论如何,我正在使用.xib并在我的视图控制器类中手动加载它。

有没有什么想法如何做到这一点?非常感谢!

回答

0

我想改变导航栏的颜色,你必须编写代码,这也是这样的:你想提供

UINavigationBar.appearance().barTintColor = UIColor.redColor() 

或任何颜色:

UINavigationBar.appearance().barTintColor = UIColor(red: 0, green: 0/255, blue: 205/255, alpha: 1) 
UINavigationBar.appearance().tintColor = UIColor.whiteColor() 
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()] 

我希望对你有所帮助。快乐编码:)

相关问题