当我通过 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/