ios – 更改UIBarbuttonItems颜色

如何将UIBarButtonItem的颜色设置为绿色?我使用的是iOS 4,没有色调属性.请帮帮我.

解决方法

在iOS 4中:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"green.png"] forState:UIControlStatenormal];
button.frame=CGRectMake(0.0,100.0,60.0,30.0);
[button setTitle:@"Green" forState:UIControlStatenormal];
[button addTarget:self action:@selector(yourAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithCustomView:button];

在这里,您需要一个绿色图像进行此操作,您正在创建一个具有此图像的自定义按钮,并将其设置为UIBarButtonItem的视图.

在iOS 5中,您可以使用:

[[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]];

请查看这些链接了解更多信息:

> UIAppearance Protocol
> User interface customization

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...