如何快速为顶部和底部单元格不是所有单元格设置 UITableViewCell 角

问题描述

您能否告诉我,如何为顶部和底部单元格而不是所有单元格为自定义 UITableViewCell 添加角辐射。请找到设计屏幕以供参考。

 c

解决方法

将您的表格视图样式设置为 .insetGrouped,自 iOS 13 起可用。

,

这是圆角的代码片段。

if indexPath.row == 0
            {
                cell.baseView.layer.cornerRadius = 10
                cell.baseView.layer.maskedCorners = [.layerMinXMinYCorner,.layerMaxXMinYCorner]
               
            }

            if indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1
            {
                cell.baseView.layer.cornerRadius = 10
                cell.baseView.layer.maskedCorners = [.layerMinXMaxYCorner,.layerMaxXMaxYCorner]
                
            }