【发布时间】:2016-03-31 00:35:20
【问题描述】:
【问题讨论】:
-
我想像上图第 1 部分那样设置角
-
我认为这在 iOS 上是不可能的
标签: ios swift uitableview
【问题讨论】:
标签: ios swift uitableview
您的 tableView 似乎包含UIView,所以只需将这些行添加到cellForRowAtIndexPath 中。如果不添加 UIView 并将半径添加到 UIView,然后将该视图添加到您的单元格 (cell.addSubView(YOURVIEW))。
cell.contentView.layer.cornerRadius = 10
cell.contentView.layer.masksToBounds = true
你可以自定义边框
cell.layer.borderColor = UIColor.grayColor().CGColor
cell.layer.borderWidth = 5
更新
将此添加到您的viewForHeaderInSection
创建一个视图 let view = UIView() 并将半径添加到您的视图中
view.layer.cornerRadius = 10
view.layer.masksToBounds = true
并添加您需要的其他属性并返回该视图。
【讨论】:
【讨论】:
cell!.contentView.layer。我怀疑是单元格的内容视图具有边框和圆角,而不是单元格。
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
{
if (tableView == self.orderDetailsTableView)
{
//Top Left Right Corners
let maskPathTop = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.TopLeft, .TopRight], cornerRadii: CGSize(width: 5.0, height: 5.0))
let shapeLayerTop = CAShapeLayer()
shapeLayerTop.frame = cell.bounds
shapeLayerTop.path = maskPathTop.CGPath
//Bottom Left Right Corners
let maskPathBottom = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.BottomLeft, .BottomRight], cornerRadii: CGSize(width: 5.0, height: 5.0))
let shapeLayerBottom = CAShapeLayer()
shapeLayerBottom.frame = cell.bounds
shapeLayerBottom.path = maskPathBottom.CGPath
//All Corners
let maskPathAll = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.TopLeft, .TopRight, .BottomRight, .BottomLeft], cornerRadii: CGSize(width: 5.0, height: 5.0))
let shapeLayerAll = CAShapeLayer()
shapeLayerAll.frame = cell.bounds
shapeLayerAll.path = maskPathAll.CGPath
if (indexPath.row == 0 && indexPath.row == tableView.numberOfRowsInSection(indexPath.section)-1)
{
cell.layer.mask = shapeLayerAll
}
else if (indexPath.row == 0)
{
cell.layer.mask = shapeLayerTop
}
else if (indexPath.row == tableView.numberOfRowsInSection(indexPath.section)-1)
{
cell.layer.mask = shapeLayerBottom
}
}
}
实际上我们正在做的是如果部分只有一行,那么我们在所有方面都这样做,如果部分有多行,那么我们在第一行的顶部和最后一行的底部......属性BottomLeft,BottomRight, topLeft,TopRight 应该是 rect 角类型(输入时来自 xcode 的建议......还有另一个同名的属性内容角......所以检查一下)
【讨论】: