更改UIBarbuttonItems颜色
我如何设置UIBarButtonItem's
颜色为绿色? 我使用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];
在这里,你需要一个绿色的图像做这个,你正在创build一个自定义button与这个图像,并将其设置为UIBarButtonItem的视图。
在iOS 5中,您可以使用:
[[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]];
请查看以下链接了解更多信息:
- UIAppearance协议
- 用户界面自定义
请尝试下面的代码。
self.navigationController.navigationBar.tintColor = [UIColor greenColor]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:NULL];
我知道这是一个老问题,但如果有人使用customView
,你可以尝试:
myButton.customView.tintColor = [UIColor blackColor];