如何为NSAttributedString的背景设置角半径?
问题描述:
我想为UILabel上的部分文本设置一个圆角半径。我有范围。
下面的代码设置背景颜色,但它会是一个矩形背景。如何为NSAttributedString的背景设置角半径?
那么,我的问题是如何设置一个圆角半径呢?
string.setAttributes([NSBackgroundColorAttributeName: UIColor.red], range: range)
谢谢你的任何建议。
答
yourLabel.layer.backgroundColor = UIColor.redColor().CGColor
yourLabel.layer.cornerRadius = 5 //Change this value as your requirement
yourLabel.layer.masksToBounds = true
愿这段代码能帮助你。
+0
此代码是对于标签上的圆角设置不适用于字符串,所以请不要发布这种类型的错误答案。 –
你可以添加一些aditional代码 –
可能重复的[NSAttributedString背景颜色和圆角](https://*.com/questions/16362407/nsattributedstring-background-color-and-rounded-corners) – BJHStudios