更改UIBarbuttonItems颜色 [英] Change UIBarbuttonItems Color

查看:103
本文介绍了更改UIBarbuttonItems颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 UIBarButtonItem的颜色设置为绿色?我正在使用 iOS 4 ,没有色彩属性。请帮助我。

How can I set UIBarButtonItem's color to green? I'm using iOS 4, there is no tint property. please help me.

推荐答案

在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的视图。

Here you need a green image for doing this, you are creating a custom button with this image and set it as the view of UIBarButtonItem.

在iOS 5中你可以使用:

In iOS 5 you can use:

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

请查看以下链接了解更多信息:

Please check these links for more:


  1. UIAppearance Protocol

  2. 用户界面自定义

  1. UIAppearance Protocol
  2. User interface customization

这篇关于更改UIBarbuttonItems颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆