【发布时间】:2017-05-10 08:50:04
【问题描述】:
我有一个自定义的UITableView 单元格。我正在设置它的左下角和右下角半径。我在cellForAtindexPath 中设置角半径。下面是该代码
if indexPath.row == 9 {
recipeInfoCell.outerView.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 10)
recipeInfoCell.layoutSubviews()
recipeInfoCell.layoutIfNeeded()
} else {
recipeInfoCell.outerView.roundCorners(corners: [.bottomLeft, .bottomRight], radius: 0)
recipeInfoCell.layoutSubviews()
}
现在,当我第一次启动 tableview 时,它不会设置任何角半径。但是当我再次滚动时,它正在设置角半径。
我创建了UIView 的扩展,其中有一个函数可以设置圆角半径
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
请告诉我如何解决这个问题?
【问题讨论】:
-
我正在做,但问题是创建单元格时不显示角半径。当我滚动表格视图时,只设置角半径
-
你第二次圆角半径,这意味着它不是圆角半径问题。它的表格视图问题。因此,请检查单元格中的条件以查找索引路径处的行。
-
但是当我像 view.cornerRadius = 10 这样设置角半径时,它就可以正常工作了
-
你试过把这段代码放入“willDisplayCell”吗?也将背景颜色修改放在那里。 developer.apple.com/reference/uikit/uitableviewdelegate/…
标签: ios uitableview cornerradius