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.
Old thread, but I wanted to chime in because I just had the same problem. The issue was just that you are calling setImage when you should call setBackgroundImage.
making the tint color as clearcolor for all the four states(Default,Highlighted,selected,disabled) worked for me.
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
To do this programmatically, add this line to the viewDidLoad
:
[UIButton buttonWithType:UIButtonTypeSystem];
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];
This Problem is called blue color problem of the button in xcode. When we make button by code the button shows the blue tint color by default.This can be solved byt assigning tint color to black or white accordingly to your cell's color. The code is :
UIImage *closebtnimg = [UIImage imageNamed:@"icon_uncheck.png"];
UIImage *closebtnimg1 = [UIImage imageNamed:@"icon_checked.png"];
Custombutton *button = [Custombutton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(52, 66, 25, 24)];
[button setBackgroundImage:closebtnimg forState:UIControlStateNormal];
[button setBackgroundImage:closebtnimg1 forState:UIControlStateSelected];
[button setTintColor:[UIColor whiteColor]];
[cell.contentView addSubview:button];
[button addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];
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.