添加2行属性字符串到UIButton的标题不起作用

时间:2015-09-01 18:53:12

标签: ios swift uibutton nsmutableattributedstring

我有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行。

1 个答案:

答案 0 :(得分:2)

试试这个:

button.titleLabel?.numberOfLines = 0;
相关问题