简体   繁体   English

如何为NSAttributedString的背景设置转角半径?

[英]How to set a corner radius for NSAttributedString's background?

I want to set a corner radius for partial text on UILabel. 我想为UILabel上的部分文本设置拐角半径。 I've got the range. 我有范围。
The following code set the background color, but it gonna be a rectangle background. 以下代码设置了背景颜色,但它将是矩形背景。

So, my problem is how to set a corner radius to it ? 那么,我的问题是如何设置拐角半径

string.setAttributes([NSBackgroundColorAttributeName: UIColor.red], range: range)

Thank you for any suggestion. 感谢您的任何建议。

yourLabel.layer.backgroundColor  = UIColor.redColor().CGColor
yourLabel.layer.cornerRadius = 5  //Change this value as your requirement
yourLabel.layer.masksToBounds = true

May this code will help you. 愿这段代码对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM