要在表视图中的自定义单元格不被圆角化,可以在自定义单元格类中重写 layoutSubviews
方法,并在该方法中设置单元格的 layer.cornerRadius
属性为0。
以下是一个示例代码:
class CustomTableViewCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
// 取消圆角化
self.layer.cornerRadius = 0
}
}
在你的表视图控制器中,注册自定义单元格类,并在 cellForRowAt
方法中使用自定义单元格类来创建单元格:
class ViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 注册自定义单元格类
tableView.register(CustomTableViewCell.self, forCellReuseIdentifier: "CustomCell")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath) as! CustomTableViewCell
// 配置自定义单元格
// ...
return cell
}
}
这样,你的自定义单元格将不会被圆角化。