Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting UIButton image results in blue button in iOS 7

In iOS7 there is new button type called UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), // standard system button

Check your .xib file and change button type to Custom Look at the image

To do this programmatically, add this line to the viewDidLoad:

[UIButton buttonWithType:UIButtonTypeSystem]; 

It seems iOS 7 is using the image provided just as an Alpha mask for displaying the button's tint color. Changing the button type to UIButtonTypeCustom did the trick for me (thanks user716216!). Setting the image as background doesn't always work if you already have a background image, as was my case.


Swift 3, 4, 5 :

let image = UIImage(named: "my-image")
myButton.setImage(image.withRenderingMode(.alwaysOriginal), for: .normal)

There's a good chance that the image is there and you just can't see it. Try changing the button's type to UIButtonTypeCustom. If that doesn't work, set the button's background color to [UIColor clearColor];


For swift:

    let aButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton

The issue is the TintColor. By default, iOS throws a blue tint color over every button. You can get around it through 3 ways.

  1. Change the tint color. [button setTintColor:[UIColor blackColor]]; This may color your image in ways you don't want it to.

  2. As most other suggested, set the background image. [button setBackgroundImage:[UIImage...]];

  3. Add an UIImageView to your button.

UIImageView * img = [[UIImageView alloc] initWithImage:[UIImage...]];

[button addSubView:img];


I had the same issue. On my storyboard I had a button without any image.

I would then assign the image in the code.

IOS 7 came and I got a lot of blue images.

The resolution was simple yet confusing. If I assign any image on the storyboard and then change the image at run time it works fine.

You always must specify a starting image on the storyboard even if you are not going to use it.