Setting UIButton image results in blue button in iOS 7

On iOS 6 SDK I wrote the following lines of code to display an image inside a button:

NSURL *thumbURL2 = [NSURL URLWithString:@"http://example.com/thumbs/2.jpg"];
NSData *thumbData2 = [NSData dataWithContentsOfURL:thumbURL2];
UIImage *thumb2 = [UIImage imageWithData:thumbData2];
[btn2 setImage:thumb2 forState:UIControlStateNormal];
[self.view addSubview:btn2];

But now with Xcode 5 and iOS 7 this doesn't work. The button doesn't contain the image. The button is filled with blue color.


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