【发布时间】:2017-09-23 10:50:27
【问题描述】:
我正在尝试在我的 iOS 应用中的表格视图上放置一个盒子阴影。我为此尝试了不同的技术,但还没有设法解决它。我尝试先在单元格本身的图层上添加阴影:
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行。
【问题讨论】:
-
我尝试了那里解释的解决方案,但没有效果。
-
你能更新一次问题吗
-
我现在更新了问题。
标签: ios iphone swift xcode uitableview