I want to populate tableview cell with this type of custom gradient color dynamically.
But can't figure out how to achieve this. I am kind of fresher in Swift programming. Any kind of help will be highly appreciable.
Thanks
I want to populate tableview cell with this type of custom gradient color dynamically.
But can't figure out how to achieve this. I am kind of fresher in Swift programming. Any kind of help will be highly appreciable.
Thanks
Hope this will help..
let layer = CAGradientLayer()
layer.frame = self.tableview.frame
let colorTop = UIColor(red: 104.0 / 255.0, green: 89.0 / 255.0, blue: 234.0 / 255.0, alpha: 1.0).cgColor
let colorBottom = UIColor(red: 106.0 / 255.0, green: 206.0 / 255.0, blue: 176.0 / 255.0, alpha: 1.0).cgColor
layer.colors = [colorTop, colorBottom]
layer.startPoint = CGPoint(x:0.5, y:0.0)
layer.endPoint = CGPoint(x:0.5, y:1.0);
self.tableview.layer.addSublayer(layer)
Note: Set clear colour to cell backgroundcolour
Try this to apply gradient in tableview
let gradient = CAGradientLayer()
gradient.frame = view.bounds
gradient.colors = [UIColor.green.cgColor, UIColor.white.cgColor]
self.tableView.separatorColor = UIColor.clear
self.tableView.layer.insertSublayer(gradient, at: 0)
And set clear color to cell background
cell.contentView.backgroundColor = UIColor.clear