【发布时间】: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