ios - UILabel swift 的圆角

标签 ios swift uilabel cornerradius

我正在以编程方式创建一个 UILabel。但是下面的代码没有给我圆角。我想我错过了一些非常基本的东西。

var textLabel:UILabel? =  UILabel()
textLabel?.text = text
textLabel?.frame = CGRect(x:point.x, y:point.y, width:(textLabel?.intrinsicContentSize.width)!, height:15)
textLabel?.backgroundColor = UIColor.white
textLabel?.font = UIFont(name:"OpenSans", size:8)
textLabel?.sizeToFit()
textLabel?.layer.cornerRadius = 20.0

谁能给我指出正确的方向?

最佳答案

我认为您应该为 textLabel 设置 maskToBounds。试试这个:

textLabel?.layer.masksToBounds = true

关于ios - UILabel swift 的圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46090400/

相关文章:

ios - 如何在触摸时向右滑动标签?

ios - iTunes 联盟计划 : Confirm if purchase is successful

android - 如何定义与另一个列表长度相同的默认列表

swift - 如何将默认 bool 值作为 true 或 false 保存到 coreData?

ios - 按下 UINavigationController 的后退栏按钮时执行操作

swift - Swift 中来自字符串的 NSDate

ios - 如何在 UIView 中安排动态创建的 UILabels?

ios - iOS 中的 UITextView 文本对齐方式

iOS Safari WebSockets : huge latency when sending messages at short intervals

ios - 如何在 iOS 9 的 UILabel 中获取等宽数字