Reputation: 131
I have the following code to present a CAGradientLayer
, which should cover the whole view. However, it shows up in the simulator not properly. I printed the values of self.view.bounds.width
and self.view.bounds.height
which printed the correct values. Below is also the simulator screenshot.
// 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)
Upvotes: 1
Views: 284
Reputation: 100541
You need to set frame
not bounds
gradientLayer.frame = self.view.frame // here frame = bounds
Upvotes: 1