IOS 7 Button Image Color

Part of mine UIButtonis this UIImage, and iOS 7 changes color from black to blue. I tried the solution suggested here: changing the button type to UIButtonTypeSystem, but this does not help, and the image still remains blue. Here is the generic code I use:

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];

Is there a solution? (and just as an aside, this is really frustrating :)

+4
source share
2 answers

C: imageWithRenderingMode:UIImageRenderingModeAlwaysOriginalsure you don't have a blue background:

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

From Apple Documentation UIImageRenderingMode :
Always draw the original image without considering it as a template:UIImageRenderingModeAlwaysOriginal

In addition, it can help you:

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

UIButtonTypeSystem UIButtonTypeCustom

+3

Source: https://habr.com/ru/post/1533700/


All Articles