David26th
David26th

Reputation: 401

Set Image of UIButton Created in Interface Builder, by code

I've got a number of UIButtons set up in Interface Builder (but all linked with appropriate outlet names). These buttons have images set up using the inspector in Interface Builder.

I would however, like to be able to change the images shown in the buttons during a certain event (so for example the user selects an appropriate settings choice and all the buttons change from displaying an image of a frog, to an image of a rabbit).

Is there a straight forward way of doing this? The change must be immediate, not on the next load.

Many thanks

Upvotes: 2

Views: 572

Answers (1)

NixonsBack
NixonsBack

Reputation: 390

Would something like, this work for you?

[button setBackgroundImage:[UIImage imageNamed:@"frog.png"] forState:UIControlStateNormal];

Upvotes: 4

Related Questions