[英]Add 2 lines of attributed string to title of UIButton not working
我有一个UIButton
。 我正在尝试使buttons title
具有2行,第二行应小于第一行。 这是我的代码:
var myMutable = NSMutableAttributedString(string: "someText\n\(someString)", attributes: [NSFontAttributeName:UIFont.systemFontOfSize(17)])
myMutable.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(14), range: NSRange(location: count("someText\n") - 1, length: count(someString) - 1))
self.myButton.setAttributedTitle(myMutable, forState: .Normal)
由于某种原因,执行此代码后什么也不会发生。 我在做什么错,该如何解决?
更新
我只是尝试为它添加颜色,并且该部分有效。 所以唯一的是,它没有2行。
尝试这个:
button.titleLabel?.numberOfLines = 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.