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];
有解决方案吗? (另外,这真是令人沮丧:)
答案 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