2013-10-16 52 views
1

更改的UIBarButtonItem風格樸素改變字體

NSDictionary * barButtonAppearanceDict = @{UITextAttributeFont : font}; 
    [[UIBarButtonItem appearance] setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal]; 

使用普通的時候不影響的UIBarButtonItem ...

如何更改爲普通樣式的UIBarButtonItem

字體這仍然適用於iOS6

回答

1

但是,這適用於我(與簡單的BarButtonItem),剛剛測試它:

[self.myBarButtonItem setTitleTextAttributes: 
[NSDictionary dictionaryWithObjectsAndKeys: 
    [UIFont fontWithName:@"Helvetica" size:22.0],NSFontAttributeName, 
    nil]forState:UIControlStateNormal]; 

對於使用外觀代理,你可以試試這個:

NSDictionary *attrDict = [NSDictionary dictionaryWithObject: [UIFont fontWithName:@"Helvetica" size:22.0] forKey: UITextAttributeFont]; 

[[UIBarButtonItem appearance] setTitleTextAttributes: attrDict 
             forState: UIControlStateDisabled]; 
[[UIBarButtonItem appearance] setTitleTextAttributes: attrDict 
             forState: UIControlStateNormal]; 

你肯定,你在你的AppDelegate實現這個 - 類? (例如,在didFinishLaunchingWithOptions - 方法)

+0

並使用NSFontAttributeName與[外觀的UIBarButtonItem],但似乎並不工作 –

+0

@PeterLapisu我」我編輯了我的答案 – falsecrypt

0

我設置的的appdelegate以下和它巨大的工作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Avenir" size:21.0]} forState:UIControlStateNormal]; 

}