Ara*_*mad 1 uiview ios shadowpath swift ios-darkmode
我有一个UIView,我shadowPath为它设置了一个这样的:
func addShadow() {
let cornerRadius: CGFloat = self.containerView.frame.height/2
self.containerView.layer.shadowPath = UIBezierPath(roundedRect: self.containerView.frame, cornerRadius: cornerRadius).cgPath
self.containerView.layer.shadowRadius = cornerRadius
self.containerView.layer.shadowOffset = .zero
self.containerView.layer.shadowOpacity = 0.2
self.containerView.layer.cornerRadius = cornerRadius
self.containerView.layer.shadowColor = UIColor(named: "whiteColor")?.cgColor
}
Run Code Online (Sandbox Code Playgroud)
这是whiteColor:
现在我的问题是
当我改变手机的外观时,
shadowPath的颜色不会自动改变。我应该怎么做才能使颜色动态?
Fra*_*gel 10
所有图层属性都不会自动对颜色变化做出反应(由于转换为CGColor)。
相反,当颜色外观发生变化时,对特征集合的变化做出反应并重新设置属性:
override open func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if #available(iOS 13, *), self.traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
// re-set your properties here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1399 次 |
| 最近记录: |