【发布时间】:2017-01-18 11:12:42
【问题描述】:
我只需要对视图的左上角和左下角进行圆角,所以我尝试了这个:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "teamCell", for: indexPath) as! TeamCell
let view = cell.backgroundCellView
let rectShape = CAShapeLayer()
rectShape.bounds = (view?.frame)!
rectShape.position = (view?.center)!
rectShape.path = UIBezierPath(roundedRect: (view?.bounds)!, byRoundingCorners: [.topRight, .topLeft], cornerRadii: CGSize(width: 20, height: 20)).cgPath
view?.layer.mask = rectShape
view?.layer.masksToBounds = true
return cell
}
它工作得很好,但是在我设置了约束(尾随、前导、顶部和底部 - 我需要一个响应式视图)之后,只有左上角是圆角的,而不是另一个。我该如何解决?
【问题讨论】:
-
以上代码在哪里?
-
在 cellForRow 中,调用 dequeueReusableCell 方法后(我要编辑我的问题)
-
在调用
super.layoutSubviews()之后,您应该尝试将其移动到您的UITableViewCell子类的layoutSubviews方法中 -
将构建掩码的代码放入单元格的 laoutSubviews 是正确答案。 @beyowulf,您应该将其发布为答案,以便 OP 可以接受。
标签: ios swift uiview constraints cornerradius