我一直在尝试将UITableViewCell的一个子类中的clipsToBounds设置为true,但不知何故它又变成了false:
class CustomCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.clipsToBounds = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
print(contentView.clipsToBounds) // false
super.layoutSubviews()
print(contentView.clipsToBounds) // false
}
}有没有理由让它在contentView中再次成为false?我可以通过在layoutSubviews()中将clipsToBounds设置为true来“修复”这个问题,但感觉不太对劲。
发布于 2017-02-28 17:12:33
您可以尝试在layoutSubviews()中设置属性。您还可以使用awakeFromNib()函数将clipsToBounds设置为true。
发布于 2017-02-28 16:01:56
我认为在您将clipsToBounds = true设置为cell.contentView之后,contentView有时会发生变化。请尝试使用cell.clipsToBounds = true。
https://stackoverflow.com/questions/42503093
复制相似问题