我在视图中有一个表格视图单元格。我希望该视图具有阴影和圆角。因此,我创建了一个类:
class UIViewWithShadowAndRoundedCorner: UIView {
@IBOutlet var roundedView: UIView!
override func layoutSubviews() {
super.layoutSubviews()
self.addShadow()
}
public func addShadow() {
self.roundedView.layer.cornerRadius = 20
self.roundedView.layer.masksToBounds = true
self.layer.shadowColor = UIColor.gray.cgColor
self.layer.shadowRadius = 1
self.layer.shadowOffset = .zero
self.layer.shadowOpacity = 1
}
override func awakeFromNib() {
super.awakeFromNib()
self.addShadow()
}
}
表格视图单元格中的视图是UIViewWithShadowAndRoundedCorner
,但我得到了这个结果(视图没有圆角,只有阴影):
如果我创建一个仅包含一个UIViewController
的项目,并且在其中包含一个UIViewWithShadowAndRoundedCorner
的实例,我会得到这个(我想要得到的结果):
为什么使用相同的视图类型会得到不同的结果?