[英]Label shadow not working in swift
I tried to give a shadow to label text but it does not shown. 我试图给阴影添加标签文本,但未显示。
My code 我的密码
private func drawValueLabel() {
valueLabel.layer.shadowColor = UIColor.red.cgColor
valueLabel.layer.shadowOffset = CGSize.init(width: 15.0, height: 15.0)
valueLabel.layer.shadowRadius = 3.0
valueLabel.layer.shadowOpacity = 1
valueLabel.layer.masksToBounds = false
valueLabel.clipsToBounds = false
valueLabel.layer.shouldRasterize = true
valueLabel.drawText(in: self.bounds)
}
Help me to show shadow 帮我显示阴影
Thanks 谢谢
I'm using this UIView extension for add shadow. 我正在使用此UIView扩展来添加阴影。 With this extension you can add shadow from storyboard.
使用此扩展程序,您可以从情节提要中添加阴影。
extension UIView {
@IBInspectable var shadow: Bool {
get {
return layer.shadowOpacity > 0.0
}
set {
if newValue == true {
self.addShadow()
}
}
}
func addShadow(shadowColor: CGColor = UIColor.black.cgColor,
shadowOffset: CGSize = CGSize(width: 1.0, height: 2.0),
shadowOpacity: Float = 0.4,
shadowRadius: CGFloat = 3.0) {
layer.shadowColor = shadowColor
layer.shadowOffset = shadowOffset
layer.shadowOpacity = shadowOpacity
layer.shadowRadius = shadowRadius
}
}
Your code is working fine for me. 您的代码对我来说很好。 Try giving some smaller offset so that you would be able to see it like
尝试提供一些较小的偏移量,以便您可以看到它
label.layer.shadowOffset = CGSize.init(width: 3.0, height: 3.0)
使用此label.layer.shadowColor = UIColor.black.cgColor label.layer.shadowOpacity = 0.5 label.layer.shadowRadius = 2.0 label.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.