我的iPhone应用程序目前正在显示一个分两部分的分组表。我试图在每个部分的第一个和最后一个单元格上更改圆角的半径(或者在只有一行的部分中,在相同的单元格上)使用以下方法:
cell.layer.cornerRadius = 4;或者在整个桌面上表演:
self.tableView.layer.cornerRadius = 4;但在执行此操作之前,我没有导入luck...Of课程,而是导入了QuartzCore。看起来,只有当表以朴素的样式显示时,才有可能自定义角。
理想的解决方案是在第一次定制上角,在最后一次定制下角。
有什么建议吗?
发布于 2012-09-19 11:38:56
最简单的方法是:
@"beginCell", @"middleCell", @"endCell"。您可以根据本教程制作它:http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中,您必须找到处于区段中间或开始/结束的ejther,并使用带有正确标识符的单元格。发布于 2019-02-22 20:24:33
以下是Swift 4.2中的工作原理,我认为也适用于Swift 5(但还没有尝试)。
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
let cornerRadius = 5
var corners: UIRectCorner = []
if indexPath.row == 0
{
corners.update(with: .topLeft)
corners.update(with: .topRight)
}
if indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1
{
corners.update(with: .bottomLeft)
corners.update(with: .bottomRight)
}
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(roundedRect: cell.bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: cornerRadius, height: cornerRadius)).cgPath
cell.layer.mask = maskLayer
}如果这在Swift 5中有效,请留下评论。
发布于 2012-09-19 09:48:38
您可以做的是在单元格的背景上添加一个UIView,使单元格背景成为透明颜色。调整UIView使其具有圆角。
https://stackoverflow.com/questions/12492200
复制相似问题