【发布时间】:2017-03-25 17:29:47
【问题描述】:
我想将我的 UITableViewController 背景颜色更改为渐变色。
我的代码如下:
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
}
然后变成黑色。
我发现了这个非常相似的问题,但它无法解决我的问题。 Set gradient behind UITableView
请帮忙! 提前致谢。
【问题讨论】:
-
我的谷歌搜索...“swift 3 渐变背景”.. 最佳结果.. stackoverflow.com/questions/24380535/….虽然这不是专门针对表格视图的,但它应该可以解决您的一个问题……然后是所有问题。
标签: uitableview swift3