UIBarButtonItem外观iOS5字体?

Jos*_*ane 0 iphone objective-c uibarbuttonitem ios

我正在使用下面的一小段代码来更改我的导航栏标题应用程序的文本属性,它工作得很好.

[[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]];
Run Code Online (Sandbox Code Playgroud)

但我希望能够轻松地为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];
Run Code Online (Sandbox Code Playgroud)

Nos*_*tap 10

您想使用- (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)stateUIBarItem 的方法(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];
Run Code Online (Sandbox Code Playgroud)