iphone - UIBarButtonItem 图标通过 IB 添加时为白色,以编程方式添加时为黑色

标签 iphone cocoa-touch uikit uibarbuttonitem

当我通过 Interface Builder 将图标添加到 UIBarButtonItem 时,该图标显示为白色。当我以编程方式将相同的图标文件添加到另一个 UIToolbar 时,该图标显示为黑色。为什么?

UIImage *image = [UIImage imageNamed:@"icon.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
rootViewController.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:reloadButton] autorelease];

最佳答案

Jongsma 说的都是对的,你应该使用 initWithImage:style: 消息。

下一个问题不是您创建UIBarButtonItem的方式,而是您分配它的位置。您可以使用 UIBarButtonItemStylePlain 创建它,它通常应将图标的轮廓呈现为白色,但 UINavigationItem 的 rightBarButtonItem(就像左侧一样)不允许使用 UIBarButtonItemStylePlain。它隐式转换为 UIBarButtonItemStyleBordered。在边框样式中,图标按“原样”呈现,为带有轻微渐变的黑色。

我认为如果您希望在有边框的 barButton 上显示白色项目,则必须触摸图像本身。

关于iphone - UIBarButtonItem 图标通过 IB 添加时为白色,以编程方式添加时为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3431961/

相关文章:

ios - 连接 iPhone 并选择 iPhone 作为设备时,Xcode 8 崩溃

iphone - NSArray 内存泄漏!无法获取为什么?

iphone - 核心数据 : Find the property of NSEntity Objects in NSMutableSet

objective-c - 是NSMutableString的-appendString : method an efficient way to build up a large string?

iphone - 推特官方SDK

iphone - 用于推送 UIViewController 的自定义动画

uikit - CLKComplication tintColor 不起作用

iphone - 来自外部设备的意外输入 - iOS

ios - 体系结构i386的 undefined symbol :用于OpenCV项目

ios - 为什么应用程序包并不总是一个包?