ios - 带有层角半径和阴影的 UILabel

标签 ios swift uikit uilabel

我正在寻找一种使用 layer.cornerRadiuslayer.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"

任何人都可以解决这个问题,以便显示 cornerRadiusshadow 吗?

最佳答案

你为什么不尝试为你的标签添加一个包含背景颜色和 cornerRadius 的父 UIView。然后保留阴影属性给标签

关于ios - 带有层角半径和阴影的 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55863161/

相关文章:

ios - UIView 数组

ios - UIWebView 嵌入视频回调在 iOS8 中不起作用?

swift - 如何在 Swift 4 中以编程方式显示 macOS 应用程序的窗口/ View Controller

ios - UITableView 多个 Action

ios - 生成图像的 UIImageView 性能问题

ios - 尝试快速更新 Realm 对象时获取 SIGABRT

ios - Swift Closure 编译器错误

ios - 无法加载 tableview 单元格 firebase 的值

ios - 即使在添加 subview 后, View 层次结构也未准备好约束

ios - 了解 UIDynamics 如何计算位置