I want to change my UITableViewController background color as gradient color.
My code is as below:
override func viewDidLoad() {
super.viewDidLoad()
let gradient = CAGradientLayer()
let gradientLocations = [0.0,1.0]
gradient.frame = view.bounds;
gradient.colors = [primaryColor, secondaryColor]
gradient.locations = gradientLocations as [NSNumber]?
let backgroundView = UIView(frame: view.bounds)
backgroundView.layer.insertSublayer(gradient, at: 0)
tableView.backgroundView = backgroundView
tableView.separatorStyle = UITableViewCellSeparatorStyle.none
tableView.backgroundColor = UIColor.clear
}
And it becomes black color.
I found this very similar question but it couldn't solve my problem. Set gradient behind UITableView
Please help! Thanks in advance.