Reputation: 6323
How can I load a jpg image into the UIButton. I want one image for when it is Not pressed. And another image for when it is pressed.
thanks
(looking to do this programmatically... no interface builder)
Upvotes: 0
Views: 225
Reputation: 46027
[myButton setBackgroundImage:[UIImage imageNamed:@"not_pressed.jpg"] forState:UIControlStateNormal];
[myButton setBackgroundImage:[UIImage imageNamed:@"pressed.jpg"] forState:UIControlStateHighlighted];
not_pressed.jpg
and pressed.jpg
are needed to be present in resource. Also you can use setImage:forState:
. Please check UIButton reference for details of these methods.
Upvotes: 3
Reputation: 28720
You can see in interface builder there are properties and you can see that there are options for backgroundImage and Image for each state(normal,highlighted,selected,disabled) go to interface builder properties of UIButton you will find there. For images to appear in the combo box you need to add images to your project.
UPDATE
Code Snippet
UIButton * btnShare=[[UIButton alloc] initWithFrame:CGRectMake(0,0,50,50)];
[btnShare setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
[btnShare setImage:[UIImage imageNamed:@"checkboxChecked.png"] forState:UIControlStateHighlighted];
[btnShare setImage:[UIImage imageNamed:@"checkboxChecked.png"] forState:UIControlStateSelected];
[btnShare addTarget: self action: @selector(accessoryButtonTapped:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
Upvotes: 0