1

My story is the following. I've added a button to a tab bar, and I have set the button identifier to 'Play' so that it looks like a play button. I am using the identifier so that I don't have to use my own 'play.png' image.

When I press the button, apart from playing a sound, I want the image (identifier) to change to 'pause'. I'm unclear if one can, and if so how to make this change.

I've seen some examples of toggling buttons from play to pause etc. but they seem to be using local image files which I want to avoid.

Any help is appreciated.

Paul.

  • 1
    This looks like it would answer your question http://stackoverflow.com/a/4288800/385017 – Craig Siemens Oct 25 '12 at 17:04
  • Moreover, it`s usually a good idea to paste the code that you`ve tried. It's easier to find the problem and people on SO will tend to help you more. – ForceMagic Oct 25 '12 at 17:19
  • Thanks, but not exactly. As I mentioned, I don't want to use external images and want to change the identifier of the UIbarbuttonitem from 'Play' to Pause'. Thanks for the tip regarding adding code, but I'm not there yet. – Armitage Shanks Oct 25 '12 at 18:12
  • From a programming point of view, I have found that the button can be initialised using initWithBarButtonSystemItem. However, I would like to know if there is a way to change this later. – Armitage Shanks Oct 25 '12 at 18:28

1 Answers1

2

I had the same problem trying to change the button style with the default identifiers on runtime, I did a google research and I think it's impossible to do this so my solution was creating a new button and changing it at runtime.

- (IBAction)playButton:(UIBarButtonItem *)sender {

if (self.scene.isPaused){
    [self.scene setPaused:YES];
    UIBarButtonItem *play = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(playButton:)];
    play.style = UIBarButtonItemStyleBordered;
    self.botToolbar.items = [NSArray arrayWithObject:play];

}
else{
    [self.scene setPaused:NO];
    UIBarButtonItem *pause = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPause target:self action:@selector(playButton:)];
    pause.style = UIBarButtonItemStyleBordered;
    self.botToolbar.items = [NSArray arrayWithObject:pause];
}

}

I use self.botToolbar.items cause I have a toolbar i added on the storyboard, if you want to use the toolbar of a NavigationController just change that for self.toolbarItems

Mark E
  • 3,403
  • 2
  • 22
  • 36