大家好我每个人都有一个带有lineHeight 1.2的UILabel并且需要它是多色的,但是一旦我改变了文本的颜色,lineheight的值就变成了默认值。 这是我的功能:
func configTopLabel(label: UILabel, localString: String, color: UIColor) {
var myString:NSString = localString
var myMutableString = NSMutableAttributedString()
myMutableString = NSMutableAttributedString(string: myString as String, attributes: [NSFontAttributeName:UIFont(name: "GothamPro-Bold", size: 22.0)!])
let location = localString.characters.count - 3
myMutableString = NSMutableAttributedString(string: myString as String, attributes: [NSFontAttributeName:UIFont(name: "GothamPro-Bold", size: 22.0)!])
myMutableString.addAttribute(NSForegroundColorAttributeName, value: color, range: NSRange(location: location,length: 3))
label.setLineHeight(1.2)
label.attributedText = myMutableString
}
答案 0 :(得分:-1)
你是否从故事板上试过了? 您可以从storyboard(属性字符串)设置多色字符串并以编程方式设置lineHeight。
答案 1 :(得分:-1)
参见上面附图,您将了解如何在故事板中制作自定义属性字符串。