热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

角半径不适用于动态分组表格

我已经基于数据动态创建了一个GroupedTableView。根据数据表视图单元格生成的自动

我已经基于数据动态创建了一个Grouped TableView。根据数据表视图单元格生成的自动高度,因此每个单元格都有不同的rowHeight。我已经使用self.tableView.rowHeight = 50

进行了相应的设置

但是问题是我使用的是拐角半径,但是我不想在每个单元格上都使用拐角半径。
我正在使用grayBox UIView及其中显示的所有单元格。角半径适用于单元格或grayBox的开始,仅适用于grayBox单元格的末尾,但适用于每个单元格。我该如何在开始和结束时应用该角radıus?

viewDidLoad()代码用于tableView行高

self.tableView.rowHeight = 50

动态分组的TableView代码:

func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.backgroundColor = UIColor.clear
cell.selectiOnStyle= .none
let grayBox = UIView(frame: CGRect(x: 5,y: 0,width: self.view.frame.size.width - 11,height: 50))
grayBox.backgroundColor = ("#cfd8dc").toColor()
grayBox.layer.cornerRadius = 5
grayBox.layer.borderColor = UIColor(red:0.80,green:0.80,blue:0.80,alpha:1.0).cgColor
grayBox.layer.borderWidth = 1.0
cell.contentView.addSubview(grayBox)
return cell
}


1-使用出队

let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!

代替

let cell = UITableViewCell()

2-通过使用标签删除在此处清除子视图

let grayBox = UIView(frame: CGRect(x: 5,y: 0,width: self.view.frame.size.width - 11,height: 50))
grayBox.tag = 333
cell.contentView.subviews.forEach {
if $0.tag == 333 {
$0.removeFromSuperview()
}
}
cell.contentView.addSubview(grayBox)

3-对于角raduis

if indexPath.row == 0 || indexPath.row == arr.count - 1 {
grayBox.layer.cornerRadius = 5
}
else {
grayBox.layer.cornerRadius = 0
}

推荐阅读
author-avatar
多米音乐_35677591
这个家伙很懒,什么也没留下!