Reputation: 528
I get a problem that I cannot set the background image to the UIButton. My button is a colour button and I want to have an image at the background of the button. And also, I can increase the size of the background image. My code is:
in .h
@property (weak, nonatomic) IBOutlet UIButton *color1;
in .m
UIImage *colorimage = [UIImage imageNamed:@"57_bg_selected"];
[_color1 setBackgroundImage:colorimage forState:UIControlStateNormal];
What I got is background image is step on the button.
Upvotes: 1
Views: 6268
Reputation: 887
Button should be of custom type to set an image. Verify your code once again. Set the button to custom type in Storyboard.
Upvotes: 1
Reputation: 4749
I have a button and this button has a back color.
Are you trying to set the background color as well as background image of the button. You can only apply one thing at a time.
Upvotes: 0
Reputation: 1918
I can see you are using IBOutlet of a button this means you are using button from nib, then you should change background image from Attributes Inspector on right side of your xcode
otherwise if you still need it to be changed programmatically then try this
[self.color1 setBackgroundImage:[UIImage imageNamed:@"57_bg_selected.png"] forState:UIControlStateHighlighted];
Please Note you should mention extension of your image .jpg or .png in your file name
Upvotes: 0