Ios UITableViewCell右侧的边框不可见
我试图在表格视图单元格周围添加边框。以下是Ios UITableViewCell右侧的边框不可见,ios,swift,uitableview,Ios,Swift,Uitableview,我试图在表格视图单元格周围添加边框。以下是cellForRowAtIndexPath中的代码: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPa
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
}
除右侧外,边界为三面:
将
maskToBounds
设置为true
图层的属性,尝试您的代码:
当此属性的值为true
时,核心动画将创建一个隐式剪裁遮罩,该遮罩与层的边界匹配,并包含任何角半径效果。如果还指定了遮罩特性的值,则将两个遮罩相乘以获得最终遮罩值。
此属性的默认值为false
您可能指定了固定宽度约束。
您应该删除它,并指定前导和尾随约束。已根据我最近的回答为单元格视图解决方案定义了
宽度
和高度
约束……因此,您想要的边框是顶部和底部的淡青色,左侧和右侧的白色以及半径?此外,构建单元的方式也存在一些问题。宽度指定为574,我敢肯定你可以把所有的布局代码移到IB@user1349663以编程方式,我只添加边框,即我保留的默认宽度。问题是我忘了为表视图本身指定约束,而不是单元格视图。@triple.s听起来你已经解决了:)如果你不能在IB中完成,我仍然会将所有单元格布局代码移到自定义单元格类中,但这可能只是个人偏好。仍然有相同的结果所以我猜单元格宽度等于屏幕宽度,对吗?是的。。我在模拟器上添加了我的xib
和应用程序的另一个快照。我猜你的边界存在,但内部对用户区域不可见。。。尝试减小单元格宽度只是为了调试我的想法…问题是我缺少tableView
的约束,而不是cellView
问题是我缺少tableView
的约束,而不是cellView
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.contentView.layer.borderWidth = 3
cell.contentView.layer.cornerRadius = 20.0
cell.contentView.layer.borderColor = UIColor.colorWithHexString("80CBC4").CGColor
cell.contentView.layer.masksToBounds = true
return cell
}