簡體   English   中英

將兩行屬性字符串添加到UIButton的標題不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM