如图所示,我想向表视图部分添加阴影。就像表视图有 4 个部分一样,表视图中也会有 4 个阴影视图。
func numberOfSections(in tableView: UITableView) -> Int {
返回 3 }
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch processIndex {
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 44
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
有一种更简单的方法来显示每个部分的阴影。
- 将表格视图的背景颜色设置为
UIColor.clear
- 将表格视图样式设置为分组(或者对于 iOS 13+,您甚至可以选择
Inset Grouped
样式也会为每个部分添加角)
- 为整个表视图添加阴影。这将为每个部分投射阴影
向表视图添加阴影:
tableView.layer.masksToBounds = false
tableView.layer.shadowColor = UIColor.black.withAlphaComponent(0.4).cgColor // any value you want
tableView.layer.shadowOpacity = 1 // any value you want
tableView.layer.shadowRadius = 100 // any value you want
tableView.layer.shadowOffset = .init(width: 0, height: 10) // any value you want
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)