Reputation: 1336
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
Thanks Everyone
Upvotes: 2
Views: 4174
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
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
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
Reputation: 4249
try creating an IBOutlet for the UIBarButtonItem.Then try changing its background image property in your code
Upvotes: 0