在UITableView单元格上放置阴影不显示[Swift 3]
我试图在我的iOS应用程序的表格视图中放置阴影。我尝试了不同的技术,但还没有设法解决它。我试图增加该小区本身的第一层上的阴影:在UITableView单元格上放置阴影不显示[Swift 3]
cell.layer.shadowColor = UIColor.black.cgColor
cell.layer.shadowOpacity = 1
cell.layer.shadowOffset = CGSize.zero
cell.layer.shadowRadius = 2
这并没有工作,所以我试图把盒子上影内容视图:
cell.contentview.layer.shadowColor = UIColor.black.cgColor
cell.contentview.layer.shadowOpacity = 1
cell.contentview.layer.shadowOffset = CGSize.zero
cell.contentview.layer.shadowRadius = 2
我还尝试在表视图单元格中添加具有相同约束的额外视图,并在该视图上放置阴影框,但这并未改变结果。 result with extra view and constraints and cornenradius
东西在表视图特别是以下内容:每节
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section != 0 {
return 10
} else {
return 0
}
}
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.tintColor = UIColor.init(netHex: 0xF9FAFD)
}
表视图的数据都放在单独的部分,和1排。
据我,你应该做以下:
1)包装在containerView所有的UITableViewCell意见。
2)为每个边上的父容器视图赋予10px的边距。
3)然后申请
cell.containerView.layer.shadowColor = UIColor.black.cgColor
cell.containerView.layer.shadowOpacity = 1
cell.containerView.layer.shadowOffset = //any offset
cell.containerView.layer.shadowRadius = 2
注:栅格化细胞层的内容,以避免总是重绘
cell.layer.shouldRasterize = true
我如何将边距添加到容器视图?我现在有这个代码:cell.backView.layer.shadowColor = UIColor.black.cgColor cell.backView.layer.shadowOpacity = 1.0 cell.backView.layer.shadowOffset = CGSize.zero cell.backView.layer。 shadowRadius = 2.0 cell.backView.layer.cornerRadius = 15结果如下:。 –
使用像领先,traling,顶部和底部约束自动布局。到10 – ankit
这是我尝试这样的结果:[带边缘的结果](http://nl.tinypic.com/r/xm9a8j/9)和[结果模拟器](http://nl.tinypic.com/r/32zl1et/9) –
看到这个曾经http://stackoverflow.com/questions/43567288/uiview-shadow -cornerradius-not-working/43567400#43567400 –
我尝试过那里解释过的解决方案,但它没有效果。 –
可以更新问题一次 –