0
在自定義階段,我試圖設置應用程序中使用的UIBarButtonItem
實例的標題屬性:UIControlStateNormal
和UIControlStateHighlighted
。無法爲高亮狀態設置UIBarButtonItem的標題文本屬性
對於.Normal
按鈕的狀態下面的代碼工作正常:
barButton.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.greenColor(), NSFontAttributeName: UIFont.systemFontOfSize(18.0)], forState: .Normal)
不過,如果我更改了狀態參數.Highlighted
代碼沒有任何影響。首先,我想也許這是目前的應用程序的錯誤,所以我創建了一個新的項目,只有一個工具欄和一個UIBarButtonItem
,但問題仍然存在。
// Has no effect
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor(), NSFontAttributeName: UIFont.systemFontOfSize(28.0)], forState: .Highlighted)
// This one has no effect too
UIBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.greenColor(), NSFontAttributeName: UIFont.systemFontOfSize(28.0)], forState: .Highlighted)
我缺少的東西或者是蘋果的bug:所以接下來的代碼什麼也不做
即使使用外觀代理設置對所有項目的title屬性有沒有影響?該文檔沒有提到關於突出顯示狀態的標題屬性UIBarButtonItem
的任何注意事項。
謝謝你的努力,但這裏有兩個問題與您的代碼:1)該按鈕的字體不改變2)如果我添加'UIToolBar'到屏幕底部然後添加'UIBarButtonItem'到這個代碼不能完全工作(我的意思是,顏色和字體都沒有改變)。對於.Normal狀態,雖然它工作得很好。 – Storix
即使建議的鏈接可以回答問題,您仍然應該將相關部分放在答案中。 –