2

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

QueueOverFlow
  • 1,336
  • 5
  • 27
  • 48
  • Does this help: http://stackoverflow.com/questions/11469908/how-to-change-background-image-on-a-button-ios – trojanfoe Sep 28 '12 at 12:06
  • @trojanfoe please see the question, i update it. – QueueOverFlow Sep 28 '12 at 12:13
  • I don't understand why you are showing the IB panel? Are you saying you want to change the image within the Xcode project programmatically, or within the running app (which is what everyone, including myself, is assuming)? – trojanfoe Sep 28 '12 at 12:21

4 Answers4

4

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]; 
TheTiger
  • 13,264
  • 3
  • 57
  • 82
0

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

AppleDelegate
  • 4,269
  • 1
  • 20
  • 27
0

image do exists only on uibutton of custom type.

So create UIButton of type custom.

Now use this button in custom view for UIBarButtonItem

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
0

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];