Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating UIImage on UiBarButtonItem from identifier to image
    text
    copied!<p>I am currently making an application for IOS but I am having trouble changing an image... what a shame... </p> <p>The situation is like this : I have a toolbar containing my items, and one of this items is the play button created from the identifier "Play". So I have my Play button without problem. Now I just want to change it to a pause image when I click on item and then switch again etc. So I liked in my .h the item giving me :</p> <pre><code>@property (weak, nonatomic) IBOutlet UIBarButtonItem *play; </code></pre> <p>I tried many answers I found on this website and none of them did work on my case :/ The last one I tried was something like this : </p> <pre><code>UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom]; [button1 setFrame:CGRectMake(10.0, 2.0, 45.0, 40.0)]; [button1 addTarget:self action:@selector(showLeft:) forControlEvents:UIControlEventTouchUpInside]; [button1 setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal]; UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1]; self.play = button; </code></pre> <p>I also tried :</p> <pre><code>self.play.customView = button1; </code></pre> <p>But none of them really work, I can get the image by doing </p> <pre><code>self.view = button1; </code></pre> <p>But that only the picture (so the creation of the UIImage is okay) in the middle of the screen so.... </p> <p>(If you can also tell me how to go back to the play using identifier it would also be very helpful thanks a lot)</p> <p>Thanks for your help. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload