IOS 7按钮图像颜色

时间:2014-03-27 10:30:43

标签: ios objective-c ios7 uibutton uiimage

UIButton的一部分是UIImage,IOS 7的颜色从黑色变为蓝色。我尝试了这里提供的解决方案:将按钮类型更改为UIButtonTypeSystem,但这没有帮助,图像仍为蓝色。这是我使用的通用代码:

UIButton *iWantPlan = [UIButton buttonWithType:UIButtonTypeSystem];
iWantPlan.frame = CGRectMake(self.view.bounds.size.width/2-bgImageWidth/2, planBg.frame.origin.y + planBg.frame.size.height + 20, bgImageWidth, bgImageWidth/4+5);
iWantPlan.titleLabel.font = [UIFont systemFontOfSize:20];
[iWantPlan addTarget:self action:@selector(goToPersonalDetails) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:iWantPlan];

iWantPlan.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
iWantPlan.imageView.frame = CGRectMake(bgImageWidth - 20, 10, 25, 25);
UIImage *viImage = [UIImage imageNamed:@"Icon_V.png"];
UIImage *viImageTap = [UIImage imageNamed:@"Icon_V_Tap.png"];
[iWantPlan setImage:viImage forState:UIControlStateNormal];
[iWantPlan setImage:viImageTap forState:UIControlStateSelected];

有解决方案吗? (另外,这真是令人沮丧:)

2 个答案:

答案 0 :(得分:9)

使用:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal确定您没有蓝色背景:

UIImage *viImage = [[UIImage imageNamed:@"Icon_V.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *viImageTap = [[UIImage imageNamed:@"Icon_V_Tap.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

来自Apple Documentation UIImageRenderingMode
始终绘制原始图像,而不将其视为模板:UIImageRenderingModeAlwaysOriginal

此外,这可以帮助您:

UIButton *iWantPlan = [UIButton buttonWithType:UIButtonTypeCustom];
...
[iWantPlan setImage:viImageTap forState:UIControlStateHighlighted];

答案 1 :(得分:3)

只需将按钮UIButtonTypeSystem的类型更改为UIButtonTypeCustom

即可