1
votes

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)

enter image description here

1
What happens if you comment out the startPoint and endPoint lines? - Nick
@Nick No change, I tested that before :( - Annabelle Sykes
@AnnabelleSykes where you try to add gradient layer? means in which method? - chirag shah

1 Answers

1
votes

You need to set frame not bounds

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