gpt4 book ai didi

ios - uiviewcontroller uiview 添加渐变层

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:04:48 26 4
gpt4 key购买 nike

我正在尝试为 UIViewController 的背景创建一个简单的渐变。我的代码是:

    let gradientLayer = CAGradientLayer()
gradientLayer.frame = view.bounds
let bottomColor = UIColor(hue: 208 / 360, saturation: 82 / 100, brightness: 0.9, alpha: 1)
let topColor = UIColor(hue: 208 / 360, saturation: 41 / 100, brightness: 0.9, alpha: 1)
gradientLayer.colors = [bottomColor, topColor]
gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.1)
gradientLayer.endPoint = CGPoint(x: 0.5, y: 0.0)

view.layer.addSublayer(gradientLayer)

渐变不显示。当我查看 View 调试器时,我没有看到它。我检查了 View 的框架,它看起来不错

x: 0, y:0, width: 375, height: 667

我也尝试了 view.layer.insert at 方法,但没有用。如果我这样做

view.layer.backgroundColor.orange

然后我确实看到了橙色背景。我错过了什么吗?

最佳答案

改变

gradientLayer.colors = [bottomColor, topColor]

gradientLayer.colors = [bottomColor.cgColor, topColor.cgColor]

关于ios - uiviewcontroller uiview 添加渐变层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48614012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com