【发布时间】:2018-06-04 20:37:54
【问题描述】:
我尝试用长 UIView 制作标准渐变上下。但它并不完整。笔尖是 UITableViewCell 的一部分,所以我无法访问 viewDidLayoutSubviews(),就像在 this thread 中一样。
我尝试从该视图的代码版本调用contentView.layoutIfNeeded()。当 UITableView cellForRowAtIndexPath 被调用时,我调用了它。但它没有效果。
我在awakeFromNib()中准备渐变。
let colors = [
UIColor(red: 33/255.0, green: 33/255.0, blue: 33/255.0, alpha: 1.0).cgColor,
UIColor(red: 51/255.0, green: 51/255.0, blue: 51/255.0, alpha: 1.0).cgColor]
let gradient = CAGradientLayer()
gradient.frame = gradientView.bounds
gradient.colors = colors
gradientView.layer.insertSublayer(gradient, at: 0)
我的代码有问题吗?
【问题讨论】:
-
我有同样的问题,请在这里查看我的答案:stackoverflow.com/questions/53974152/…
标签: ios swift uitableview uiview cagradientlayer