Swift - 设置tableView每个分区cell圆角

这篇博客介绍了如何在Swift中为UITableView的每个分区的cell设置圆角。通过重写`tableView(_:willDisplayCell:forRowAtIndexPath:)`方法,利用CAShapeLayer和CGPath创建圆角,并设置cell的背景颜色和边框。代码分别处理了分区第一行、最后一行和中间行的圆角绘制,确保了不同位置cell的圆角效果。
摘要由CSDN通过智能技术生成
 

1.// 重新绘制cell边框

    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

            let cornerRadius: CGFloat = 10            

            cell.backgroundColor = UIColor.clearColor()

            let layer = CAShapeLayer()

            let pathRef = CGPathCreateMutable()    

            let bounds = CGRectInset(cell.bounds, 10, 0)

            var addLine = false

            if indexPath.row == 0 && indexPath.row == tableView.numberOfRowsInSection(indexPath.section)-1 {

                CGPathAddRoundedRect(pathRef, nil, bounds, cornerRadius, cornerRadius)

            } else if indexPath.row == 0 {

                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMaxY(bounds))

                CGPathAddArcToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetMidX(bounds), CGRectGetMinY(bounds), cornerRadius)

                CGPathAddArcToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMinY(bounds), CGRectGetMaxX(bounds), CGRectGetMidY(bounds), cornerRadius)

                CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(bounds), CGRectGetMaxY(bounds))

                addLine = true

            } else if indexPath.row == tableView.numberOfRowsInSection(indexPath.section)-1 {

                CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(bounds), CGRectGetMinY(bounds))

                CGPathAddArcToPoint(pathRef, nil, CGRectGetM

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值