2014-03-06 47 views
2

我試圖設置禁用textAttributesUIBarButtonItemUIToolbarUIBarButtonItem不顯示禁用狀態titleTextAttributes

創建我的項目,像這樣:

NSDictionary *enabledAttrs = @{ NSFontAttributeName    : font, 
            NSForegroundColorAttributeName : color }; 

NSDictionary *disabledAttrs = @{ NSFontAttributeName    : font, 
            NSForegroundColorAttributeName : [UIColor grayColor] }; 

[item setTitleTextAttributes:enabledAttrs forState:UIControlStateNormal]; 
[item setTitleTextAttributes:disabledAttrs forState:UIControlStateDisabled]; 

然而,當我設置item.enabled = NO,按鈕被禁用(它不火的動作),但它並沒有履行titleTextAttributes - 它仍然會出現在正常狀態。爲什麼?

+0

是U肯定要設置的屬性?你想改變背景顏色還是前景? – tiguero

回答

0

創建UIButton並用UIBarbutton包裝,我認爲它應該是工作。

UIButton *uiButton = [[UIButton alloc] init]; 
[uiButton setTitleColor: color1 forState: UIControlStateNormal]; 
[uiButton setTitleColor: color2 forState: UIControlStateDisabled]; 

UIBarButtonItem *uiBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:uiButton];