我有以下代码来呈现CAGradientLayer
,它应该覆盖整个视图。但是,它不能正确显示在模拟器中。我打印了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)
答案 0 :(得分:0)
您需要设置frame
而不是bounds
gradientLayer.frame = self.view.frame // here frame = bounds