ebaccount
ebaccount

Reputation: 5051

iPhone image button

I want to use image buttons in my iPhone application. Could you please let me know if there is any article I can read on this.

Thanks.

Upvotes: 4

Views: 20075

Answers (5)

user382968
user382968

Reputation: 21

you dont need to release img. So the correct code could be -

UIButton *btn = [[UIButton alloc] init];
UIImage *img = [UIImage imageNamed:@"image.png"];
[btn setImage:img forState:UIControlStateNormal];

Upvotes: 2

andre.wiik
andre.wiik

Reputation: 31

In Interface Builder you can choose a Custom button and then set the Image property to your image. Don't use Rounded rect button, it will show behind the image.

Upvotes: 1

stefanB
stefanB

Reputation: 79770

So the suggestion from http://www.iphonedevsdk.com/forum/iphone-sdk-development/1891-changing-button-image-code.html is:

UIButton *btn = [[UIButton alloc] init];
UIImage *img = [UIImage imageNamed:@"image.png"];
[btn setImage:img forState:UIControlStateNormal]
//No need to release img. It is autoreleased!!!

Upvotes: 10

Jurgis
Jurgis

Reputation: 311

But you need to release the button ;) [btn release];

Upvotes: 0

nivnad
nivnad

Reputation: 716

Programatically, you can do something like this... http://www.iphonedevsdk.com/forum/iphone-sdk-development/1891-changing-button-image-code.html

Upvotes: 1

Related Questions