user3763526
user3763526

Reputation: 65

Hit button once to show UIImage. Hit button again to hide UIImage

I researched on this website but couldn't find anything to help me. I'm a beginner in coding so this may seem simple to some of you but hard for me. I have an instruction button in my game that i press to show a speech bubble giving the user instruction. I am trying to achieve, when I repress the instruction button, the speech bubble should disappear.

.h

IBOutlet UIImageView *instructionsPic;
- (IBAction)instructionAction;

.m

    - (IBAction)instructionAction {
    instructionsPic.hidden = NO;
    startGameButton.hidden = YES;
}

In my viewDidLoad i marked my instruction bubble speech as hidden and when the user hits the instruction button it shows up. So yea, how can i make it disappear again when they click the button again?

Upvotes: 0

Views: 48

Answers (1)

tek3
tek3

Reputation: 2115

You have to toggle the hidden property of your 'instructionsPic' each time 'instruction' button is pressed.

You can change your IBAction method to :

- (IBAction)instructionAction {
instructionsPic.hidden = !instructionsPic.hidden;
startGameButton.hidden = !startGameButton.hidden;
}

I leave it upto you to understand the logic used here.

Upvotes: 1

Related Questions