Reputation: 21
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.
Upvotes: 1
Views: 3757
Reputation: 3483
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
Upvotes: 2