我的应用程序中有带浅色背景的UIBarButtonItems,并且我想将图标着色为较暗的颜色,而不是标准的白色。
就像这样:
我能够使用
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor blackColor]} forState:UIControlStateNormal];,
但是我不知道如何更改图标的颜色。
这个有可能吗?
我的应用程序中有带浅色背景的UIBarButtonItems,并且我想将图标着色为较暗的颜色,而不是标准的白色。
就像这样:
我能够使用
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeTextColor: [UIColor blackColor]} forState:UIControlStateNormal];,
但是我不知道如何更改图标的颜色。
这个有可能吗?
UIImage *buttonImage = [UIImage imageNamed:@"image"]; // Tint this image programmatically
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
tintColor
免费获得此行为。[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];
[myBarButton_name setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor yellowColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
UIBarButtonItem
上色。只需设置按钮的tintColor
即可。 - rmaddytintColor
颜色,我们可以改变UIBarButtonItem
的颜色而不是图像颜色。 OP只想改变内置UIBarButtonItem
图像的颜色。就像http://i.stack.imgur.com/AUPfh.png这样。 - iPatel