iphone - 如何更改 UIBarButton 项的字体颜色?

标签 iphone objective-c cocoa-touch interface-builder uibarbuttonitem

我想把颜色改成红色。

最佳答案

我找到了一种更简单的方法来改变标题的颜色: iOS7:

UIBarButtonItem *button = 
 [[UIBarButtonItem alloc] initWithTitle:@"Title" 
                                  style:UIBarButtonItemStyleBordered 
                                 target:nil 
                                 action:nil];
[button setTitleTextAttributes:
          [NSDictionary dictionaryWithObjectsAndKeys: 
               [UIColor redColor], NSForegroundColorAttributeName,nil] 
                                            forState:UIControlStateNormal];

和之前的 iOS7:

UIBarButtonItem *button = 
  [[UIBarButtonItem alloc] initWithTitle:@"Title" 
                                   style:UIBarButtonItemStyleBordered 
                                  target:nil 
                                  action:nil];
[button setTitleTextAttributes:
          [NSDictionary dictionaryWithObjectsAndKeys: 
               [UIColor redColor], UITextAttributeTextColor,nil] 
                                    forState:UIControlStateNormal];

关于iphone - 如何更改 UIBarButton 项的字体颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3314035/

相关文章:

iphone - 了解 iPhone OpenGL 分析

iphone - 文件缓存问题

iphone - 显示警报 View 后如何移动到下一个 View Controller

objective-c - 在 UITabBarController 中重新排序 View Controller ,所有这些都在 Storyboard 中定义

ios - 具有不同格式的多行标题 UINavigationBar

ios - 似乎我的应用程序正在以错误的顺序执行操作

iphone - 如何释放一个 NSMutableArray?

iphone - -[NSCF字典长度] : unrecognized selector

ios - 在运行时更改方向更改 ViewControllers

android - 如何在 Objective-C 中将值 BOOL 设置为与 Firebase 中的 Java 相同?