我正在寻找一种显示带有UILabel
和layer.cornerRadius
的{{1}}的方法。
我发现,使用layer.shadow
会设置label.clipsToBounds = true
,使用cornerRadius
会显示阴影
仅显示阴影,不显示cornerRadius
label.masksToBounds = false
任何人都可以解决此问题,以便显示let label = UILabel()
label.textAlignment = .center
label.font = UIFont.systemFont(ofSize: 32, weight: .regular)
label.textColor = .white
label.clipsToBounds = true
label.backgroundColor = Colors.Vibrants.softBlue
label.layer.cornerRadius = 50
label.layer.masksToBounds = false
label.layer.shadowColor = UIColor.black.cgColor
label.layer.shadowOffset = CGSize(width: 5, height: 5)
label.layer.shadowRadius = 5
label.layer.shadowOpacity = 0.7
label.text = "0"
和cornerRadius
吗?
答案 0 :(得分:1)
为什么不尝试为标签添加父项 "<img width=\"" + pixelPerCm + "\" height=\"" + pixelPerCm + "\" src=\"" + imagePath + "\" " + sStyle + ">"
,该父项将包含背景颜色和cornerRadius。然后将阴影属性保留到标签上
答案 1 :(得分:1)
URLSessionDidFinishEventsForBackgroundURLSession
答案 2 :(得分:0)
class setShadowOnLabel: UILabel
{
override func layoutSubviews()
{
self.layer.cornerRadius = 5
self.layer.shadowColor = UIColor.lightGray.cgColor
self.layer.shadowOffset = CGSize(width: 0.0, height: 0.2)
self.layer.shadowOpacity = 0.80
self.layer.shadowRadius = 5.0
self.layer.masksToBounds = false
}
}