我有一个自定义的 UITableViewCell
,带有一个自调整大小的 UILabel
和一个阴影。
class CustomCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var cellBackgroundView: UIView!
@IBOutlet weak var creationDateLabel: UILabel!
override func layoutSubviews() {
super.layoutSubviews()
self.cellBackgroundView.layer.cornerRadius = 12
self.cellBackgroundView.layer.shadowColor = UIColor.black.withAlphaComponent(1.0).cgColor
self.cellBackgroundView.layer.shadowOffset = CGSize.zero
self.cellBackgroundView.layer.shadowRadius = 9
self.cellBackgroundView.layer.shadowOpacity = 0.8
self.cellBackgroundView.layer.shadowPath = UIBezierPath(rect: self.cellBackgroundView.bounds).cgPath
self.cellBackgroundView.layer.masksToBounds = false
self.cellBackgroundView.layer.shouldRasterize = true
self.cellBackgroundView.layer.rasterizationScale = UIScreen.main.scale
}
}
我尝试在 layoutSubviews()
、cellForRowAt: indexPath
和 willDisplay cell
中实现此代码,但它始终处于关闭状态居中:
编辑:当我开始在 tableView 中滚动时它会起作用。
编辑 2: 它应该是这样的:
谢谢!
最佳答案
试试你发布的代码没有这一行:
self.cellBackgroundView.layer.shadowPath = UIBezierPath(rect: self.cellBackgroundView.bounds).cgPath
这应该可以解决问题。
关于ios - 自动调整 UITableViewCell 阴影大小已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44372422/