在iOS7中,我创建了一个
以下是代码:
UIBarButtonItem
,并使用绿色的图片进行初始化。但是最终这个UIBarButtonItem
的图片外观是相同形状但颜色不同的图片。颜色被改变成了蓝色。以下是代码:
_recordVoiceItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"voiceIcon"] style:UIBarButtonItemStylePlain target:self action:nil];
_textView = [[UITextView alloc] initWithFrame:CGRectMake(40, 4, 220, BOTTOM_BAR_HEIGHT - 2*4)];
_textView.layer.borderWidth = 1.f;
_rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"modeIcon"] style:UIBarButtonItemStylePlain target:self action:nil];
_bottomBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.origin.y + self.view.frame.size.height - BOTTOM_BAR_HEIGHT, self.view.frame.size.width, BOTTOM_BAR_HEIGHT)];
_bottomBar.items = @[_recordVoiceItem,[[UIBarButtonItem alloc] initWithCustomView:_textView],_rightItem];
[self.view addSubview:_bottomBar];
我尝试通过Interface Builder创建UIToolBar
并添加一些项目,外观很好。但是UIBarButtonItem
图像的颜色是原始图像的颜色。
我怀疑如果我想通过编写代码来完成这个操作,我需要添加一些代码来设置UIToolBar
或UIBarButtonItem
的某些属性。你能告诉我如何做吗?
tintColor
和UIImage
中的新 API 是我见过的最糟糕的 API 设计失败。在tintColor
的文档中,苹果应该添加一个链接到这个UIImage
方法。 - Marek R