ios - UITableViewCell 圆角问题

标签 ios iphone swift sdk

enter image description here

我想把最后一个 UITableViewCell 底角做成圆形,我可以做到,但结果是边界没有正确绘制,任何人都对此类问题有同样的经验,请帮我。谢谢

cell.roundCorners([.bottomLeft, .bottomRight], radius: 8)
cell.clipsToBounds = true
cell.layer.masksToBounds = true
cell.layoutSubviews()

最佳答案

使用 UIBezierPath 圆角到最后一个单元格

    let totalRow : Int = tableView.numberOfRows(inSection: indexPath.section)
    //first get total rows in that section by current indexPath.
    if indexPath.row == totalRow - 1 {
        //this is the last row in section.

        let maskLayer = CAShapeLayer()
        maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [.bottomLeft,.bottomRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath
        cell.layer.mask = maskLayer
    }else{

        let maskLayer = CAShapeLayer()
        maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [], cornerRadii: CGSize(width: 0, height: 0)).cgPath
        cell.layer.mask = maskLayer
    }

关于ios - UITableViewCell 圆角问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50487389/

相关文章:

ios - 未找到 Cordova 4.0.1 CDV 摄像头 <Cord​​ova/NSData+Base64.h>

ios - 构建Cordova 3.4应用程序时体系结构i386的 undefined symbol

iphone - 没有 Storyboard或 xib 文件的 iOS 通用应用程序

iphone - 如何从核心数据库获取数据

c# - 使用 C# 停止 Unity3d 中的线程

ios - iPad Mini 未获取 UIImage 值

ios - 单击完成按钮后 UITexfled 保持焦点

ios - 我可以直接在场景的 sprite kit 节点中响应触摸,还是需要通过场景的 touchesBegan 方法

ios - swift 3 : How to mute/unmute microphone during video recording using AVFoundation

ios - Swift1.2中可空性注释的默认值是多少