ios – 停止CALayer影子影响子视图?

ios – 停止CALayer影子影响子视图?,第1张

概述我有一个定制的UIControl,我希望它有一个阴影,所以我设置相关属性在它的图层.在视图周围出现阴影,但阴影也会出现在UILabel的文本下,该文本是子视图.你如何阻止这个?我只想要外部超级视野的影子. ...init() { label = UILabel() label.translatesAutoresizingMaskIntoConstraints = 我有一个定制的UIControl,我希望它有一个阴影,所以我设置相关属性在它的图层.在视图周围出现阴影,但阴影也会出现在UILabel的文本下,该文本是子视图.你如何阻止这个?我只想要外部超级视野的影子.
...init() {            label = UILabel()    label.translatesautoresizingMaskIntoConstraints = false    self.translatesautoresizingMaskIntoConstraints = false    addSubvIEw(label)    self.layer.masksToBounds = false    self.layer.shadowcolor = UIcolor.blackcolor().CGcolor    self.layer.shadowOpacity = 1.0    self.layer.shadowRadius = 2.0    // Adding these lines trying to explicitly stop shadow on label...    label.layer.shadowOpacity = 0    label.layer.shadowcolor = nil    ...}
解决方法 当父视图的Alpha值小于1.0或没有背景颜色(即设置为清除颜色)时,会发生这种情况.在这种情况下,阴影转换为子视图.有关详细信息,请参阅我的答案 here.

苹果Docs证明了这一点:

figure A-7 shows several different versions of the same sample layer with a red shadow applIEd. The left and mIDdle versions include a background color so the shadow appears only around the border of the layer. However,the version on the right does not include a background color. In this case,the shadow is applIEd to the layer’s content,border,and sublayers.

总结

以上是内存溢出为你收集整理的ios – 停止CALayer影子影响子视图?全部内容,希望文章能够帮你解决ios – 停止CALayer影子影响子视图?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1095841.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存