【发布时间】:2016-07-24 21:07:53
【问题描述】:
我正在尝试在表格视图单元格周围添加边框。以下是cellForRowAtIndexPath中的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.separatorInset.left = 20.0
cell.separatorInset.right = 20.0
cell.separatorInset.top = 20.0
cell.separatorInset.bottom = 20.0
cell.layer.borderWidth = 3
cell.layer.cornerRadius = 20.0
cell.layer.borderColor = UIColor.colorWithHexString("80CBC4").CGColor
return cell
}
【问题讨论】:
-
已为单元格视图定义了
width和height约束 -
从我最近的回答中尝试解决方案...
-
所以你想要的边框是顶部和底部的浅蓝绿色,左右两侧的半径为白色?此外,构建单元的方式也存在一些问题。例如。宽度指定为 574,我很确定您可以将所有布局代码移动到 IB
-
@user1349663 以编程方式,我只添加边框,我留下的宽度作为默认值。问题是我忘记为表格视图本身指定约束,而不是单元格视图。
-
@triple.s 听起来你已经明白了 :) 如果你不能在 IB 中这样做,我仍然会将所有单元格布局代码移动到自定义单元格类中,但这可能只是个人喜好。
标签: ios swift uitableview