【问题标题】:Set background in UIViewController inside navigation controller在导航控制器内的 UIViewController 中设置背景
【发布时间】:2017-09-11 06:00:09
【问题描述】:

我想用渐变色设置我的背景色全屏(包括导航栏和状态栏)。现在,我通过创建渐变来做到这一点

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 中添加了层。它可以工作,但不会掩盖状态栏和导航栏。看这张图片:

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

有什么想法吗?非常感谢!

【问题讨论】:

    标签: ios swift uiviewcontroller uinavigationcontroller


    【解决方案1】:

    我猜想改变导航栏的颜色你必须为它编写代码也是这样的:

    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()]
    

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

    【讨论】:

      猜你喜欢
      • 2020-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多