给不工作的UIButton的标题添加2行属性字符串



我有一个UIButton。我试着让buttons title有2条线,第二条线应该比第一条线小。下面是我的代码:

var myMutable = NSMutableAttributedString(string: "someTextn(someString)", attributes: [NSFontAttributeName:UIFont.systemFontOfSize(17)])
myMutable.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(14), range: NSRange(location: count("someTextn") - 1, length: count(someString) - 1))
self.myButton.setAttributedTitle(myMutable, forState: .Normal)

由于某种原因,在执行这段代码时什么也没有发生。我做错了什么?我该如何补救?

我只是试着给它添加颜色,这部分工作。唯一的问题是,它没有两行

试试这个:

button.titleLabel?.numberOfLines = 0;

最新更新