1

In IOS 7, in my xib files if I set a button type to UIButtonTypeSystem, I can change the button tint color to whatever I want.

Can I do this programmatically? I can't seem to, I've tried the same image on xib and it works fine.

This is what I'm doing:

//Date picker button
            self.dateButton=[UIButton buttonWithType:UIButtonTypeSystem];
            self.dateButton.frame=CGRectMake(x, y, 30, 30);
            self.dateButton.tintColor = [UIColor colorWithRed:91.0/255.0 green:146.0/255.0 blue:213.0/255.0 alpha:1.0];
            [self.dateButton setBackgroundImage:[UIImage imageNamed:@"calendarButton.png"] forState:UIControlStateNormal];
Cœur
  • 37,241
  • 25
  • 195
  • 267
JDM
  • 883
  • 1
  • 8
  • 20
  • possible duplicate of [change image tintColor in ios7](http://stackoverflow.com/questions/19274789/change-image-tintcolor-in-ios7) – Howli May 24 '14 at 21:54
  • You are setting the `backgroundImage` on the button, which overwrites the `tintColor` property. What you can do to work around this is tint your image[as described here](http://stackoverflow.com/questions/19274789/change-image-tintcolor-in-ios7). – David Ganster Apr 29 '14 at 21:59

1 Answers1

0

You are putting your tint Color on the wrong atribute, you should change the 'tintColor' to the 'backgroundColor', like this:

self.dateButton.backgroundColor = [UIColor colorWithRed:91.0/255.0 green:146.0/255.0 blue:213.0/255.0 alpha:1.0];