I have a gradient layer set for a table view, using the following code:
func setGradientToTableView(_ topColor:UIColor, _ bottomColor:UIColor) {
let gradientBackgroundColors = [topColor.cgColor, bottomColor.cgColor]
let gradientLocations = [0.0,1.0]
let gradientLayer = CAGradientLayer()
gradientLayer.colors = gradientBackgroundColors
gradientLayer.locations = gradientLocations as [NSNumber]
gradientLayer.frame = tableView.bounds
let backgroundView = UIView(frame: tableView.bounds)
backgroundView.layer.insertSublayer(gradientLayer, at: 0)
tableView.backgroundView = backgroundView
}
And this:
setGradientToTableView(UIColor(red: 125/255.0, green: 125/255.0, blue: 125/255.0, alpha: 1.0), UIColor(red: 125/255.0, green: 125/255.0, blue: 0/255.0, alpha: 1.0)).
The problem is coming when I run the app. The gradient layer will be the size of the table view for the device and orientation that is selected in the storyboard.
Does anyone know how to fix this? - btw my constraints for the table view are navigation bar bottom, leading, trailing, and safe area bottom
Edit: Here is a screenshot