QueueOverFlow
QueueOverFlow

Reputation: 1336

add image programmatically on toolbar item button

I add a Round Rect Button on toolbar and place a image in button through xib, Now I have to change image programmatically, how we can change button image programmatically in Toolbar, I googling but not get the solution yet.

I wants to change the button image programmatically , please see the image below

enter image description here

Thanks Everyone

Upvotes: 2

Views: 4174

Answers (4)

user2289379
user2289379

Reputation:

Create an UIBarButtonItem with an image and add it..!?

Example:

UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithImage: yourImage style: UIBarButtonItemStyleBordered target: nil action: nil];

If you don't want the button appeareance, try to use:

UIBarButtonItem* item = [UIBarButtonItem initWithCustomView: yourImageView];

Upvotes: 0

Paresh Navadiya
Paresh Navadiya

Reputation: 38239

image do exists only on uibutton of custom type.

So create UIButton of type custom.

Now use this button in custom view for UIBarButtonItem

Upvotes: 0

TheTiger
TheTiger

Reputation: 13354

Set your button IBOutLet which you're using for your BarButtonItem and then change your button image programmatically.

[button setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal]; 

Upvotes: 4

AppleDelegate
AppleDelegate

Reputation: 4249

try creating an IBOutlet for the UIBarButtonItem.Then try changing its background image property in your code

Upvotes: 0

Related Questions