我有一个包含自定义单元格的tableview
,这些单元格是使用带有标识符的AutoLayout
构建的storyboard
。
其中一个子视图
需要变成圆形(layer.cornerRadius = width/2)
,它一开始是正方形。
我尝试在layoutSubviews()
中实现,但似乎在AutoLayout
改变大小之前就已被调用了...didMoveToSuperview()
也一样。
在AutoLayout
更改其大小后,更新我的子视图类似于这样的东西的正确函数在哪里?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell_small") as! Cell
...
return cell
}
// In Cell
override func layoutSubviews() {
rankLabel.layer.cornerRadius = rankLabel.bounds.width/2
rankLabel.layer.masksToBounds = true
}
override func didMoveToSuperview() {
rankLabel.layer.cornerRadius = rankLabel.bounds.width/2
rankLabel.layer.masksToBounds = true
}
结果: 解释: 无需翻译。
- (void) layoutSubviews
方法中添加了两行代码。确实解决了问题,但是在单元格显示一段时间后会出现明显的形状改变。 - JonSlowCN