gpt4 book ai didi

swift - CAGradientLayer 框架无法正确显示

转载 作者:行者123 更新时间:2023-11-30 11:16:20 25 4
gpt4 key购买 nike

我有以下代码来呈现一个CAGradientLayer,它应该覆盖整个 View 。但是,它在模拟器中显示不正确。我打印了 self.view.bounds.width 和 self.view.bounds.height 的值,它们打印了正确的值。下面也是模拟器截图。

// Add background layer to calendar view
let gradientLayer = CAGradientLayer()
gradientLayer.bounds = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)
gradientLayer.colors = [lightDarkColor.cgColor, darkColor.cgColor, lightDarkColor.cgColor]
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.0)
gradientLayer.endPoint = CGPoint(x: 1.0, y: 1.0)
self.view.layer.insertSublayer(gradientLayer, at: 0)

enter image description here

最佳答案

您需要设置frame而不是bounds

gradientLayer.frame = self.view.frame // here frame = bounds

关于swift - CAGradientLayer 框架无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51709276/

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