我有一个可变的文本,有一个背景颜色和圆角。所以我将UILabel与NSMutableAttributedString结合使用。
myAttributedString = NSMutableAttributedString(string:"hello")
myAttributedString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.red, range: NSRange(location: 0, length: myAttributedString.length))
myLabel.attributedText = myAttributedString
myLabel.layer.cornerRadius = 5
myLabel.clipsToBounds = true
myLabel.layer.masksToBounds = true我只得到一面有圆角的标签。我该怎么做才能使四面八方都变成圆角?

发布于 2017-03-23 13:02:37
只是增加了UILabel (myLabel)的宽度
let myAttributedString = NSMutableAttributedString(string:"hello")
myAttributedString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.red, range: NSRange(location: 0, length: myAttributedString.length))
myLabel.attributedText = myAttributedString
myLabel.layer.cornerRadius = 5
myLabel.clipsToBounds = true
myLabel.layer.masksToBounds = true
// your code is right
// just increase the width of UILabel (myLabel)https://stackoverflow.com/questions/42976044
复制相似问题