9

因此,我在iOS 7中遇到了UIBarButtonItem外觀問題。有一個屬性,我找不到任何文檔,似乎設置導航欄按鈕的不透明度時按下,我不知道如何修改它。UIBarButtonItems選擇的顏色不會在iOS 7中正確更改

[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]]; 
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor whiteColor]} forState:UIControlStateNormal]; 
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor orangeColor]} forState:UIControlStateHighlighted]; 

對於此代碼,我得到的結果如下所示。

Normal Button Highlighted Button

我不知道是怎麼回事。第一個問題是,我似乎無法得到箭頭色調(因爲沒有setTintColor:forState:方法)。第二個問題是按下這個可怕的不透明/色調。謝謝!

+0

因爲你必須設置uiimage selected/unselected。 –

+1

您是否找到了文本顏色的解決方案? – ArtFeel

回答

1

//定製返回欄按鈕粘貼此代碼的appdelegate

UIImage *buttonBack30 = [[UIImage imageNamed:@"button_back_textured_30"] 
         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)]; 
UIImage *buttonBack24 = [[UIImage imageNamed:@"button_back_textured_24"] 
         resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)]; 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 
                forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24 
                forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone]; 
+0

我實際上只想着色文字,而不是設置圖像! – Rob

1

你需要實現這個低於ios7二方法爲UIBarButtonItem

@property(nonatomic, retain) UIColor *tintColor 
- (void)setBackButtonBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics 
+0

我只是嘗試着色文本,沒有設置背景圖片。 :) – Rob

1

嘗試以下解決方案它可能工作

NSDictionary *attributes = [NSDictionary  dictionaryWithObjectsAndKeys:[UIFont 
fontWithName:@"YOURFONT" size:14], NSFontAttributeName, 
[UIColor whiteColor], NSForegroundColorAttributeName, nil]; 
    [[UINavigationBar appearance] setTitleTextAttributes:attributes];