Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS 7 button image color

Part of my UIButton is an UIImage, and IOS 7 changes its color from black to blue. I tried the solution offered around here: changing the button type to UIButtonTypeSystem but that doesn't help and the image is still blue. Here's the generic code I'm using:

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 :)

like image 726
Eddy Avatar asked Dec 16 '22 00:12

Eddy


1 Answers

With: imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal sure you don't have the 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 treating it as a template: UIImageRenderingModeAlwaysOriginal

Also, that can help you:

UIButton *iWantPlan = [UIButton buttonWithType:UIButtonTypeCustom];
...
[iWantPlan setImage:viImageTap forState:UIControlStateHighlighted];
like image 130
Gabriel.Massana Avatar answered Jan 04 '23 06:01

Gabriel.Massana