0

以下のようなコードの小さなチャンクを使用して、ナビゲーション バーのタイトル アプリ全体のテキスト属性を変更していますが、うまく機能します。

[[UINavigationBar appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor whiteColor], UITextAttributeTextColor,
      [UIColor grayColor], UITextAttributeTextShadowColor,
      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
      [UIFont fontWithName:@"Cochin-BoldItalic" size:0.0], UITextAttributeFont,
      nil]];

しかし、UIBarButtonItemテキストに対してもこれを簡単に実行できるようにしたいのですが、表示される同じまたは類似のメソッドを共有していないため、わかりません。

編集

テキストに変更を加えずに、このコードを試しました:

[[UIBarItem appearance] setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor whiteColor], UITextAttributeTextColor,
      [UIColor grayColor], UITextAttributeTextShadowColor,
      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
      [UIFont fontWithName:@"Cochin-BoldItalic" size:12.0], UITextAttributeFont,
      nil]
     forState:UIControlStateNormal];
4

2 に答える 2

10

UIBarItemのメソッドを使用したい- (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state(UIBarButtonItem は UIBarItem を継承しています)。

詳細については、ドキュメントをご覧ください: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarItem_Class/Reference/Reference.html#//apple_ref/occ/cl/UIBarItem

これを試して:

//Suppose you have initialized barButton elsewhere`
[barButton setTitleTextAttributes:
     [NSDictionary dictionaryWithObjectsAndKeys:
      [UIColor whiteColor], UITextAttributeTextColor,
      [UIColor grayColor], UITextAttributeTextShadowColor,
      [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
      [UIFont fontWithName:@"Cochin-BoldItalic" size:12.0], UITextAttributeFont,
      nil]
     forState:UIControlStateNormal];
于 2012-07-19T21:13:13.150 に答える
0

これは iOS 7.1 で動作するようです:

[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
                                 NSFontAttributeName:[UIFont fontWithName:@"Resamitz" size:16.0]}
                                            forState:UIControlStateNormal];
于 2014-04-29T08:41:42.930 に答える