我正在寻找一种使用 layer.cornerRadius
和 layer.shadow
显示 UILabel
的方法。
我发现,使用 label.clipsToBounds = true
将设置 cornerRadius
,使用 label.masksToBounds = false
将设置阴影显示
只有阴影,没有cornerRadius才会显示
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
和 shadow
吗?
最佳答案
你为什么不尝试为你的标签添加一个包含背景颜色和 cornerRadius 的父 UIView
。然后保留阴影属性给标签
关于ios - 带有层角半径和阴影的 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55863161/