我使用下面的代码在UIBarButtonItem上显示图像
UIBarButtonItem *myButtonItem;
myButtonItem= [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image.png"] style:UIBarButtonItemStylePlain target:self action:@selector(pressB:)];
但图像颜色为两种颜色(红色/蓝色),但ButtonItem上显示的图像为白色。
Iy看起来像IOS自动将其变为白色。
欢迎任何评论
答案 0 :(得分:1)
而不是仅仅分配initWithImage:如果你想在app中的所有UIBarButtonItems上添加相同的图像,你可以在appdelegae.m中使用这个方法
- (void)customizeAppearance
{
// Customize the UIBarButtonItem
// Create resizable images
UIImage *button30 = [[UIImage imageNamed:@"button_textured_30"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
UIImage *button24 = [[UIImage imageNamed:@"button_textured_24"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:button24 forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
}