Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the alpha of a UILabel by tapping?

I have an iOS (4.0) app that I would like to change the alpha of a specific UILabel of just by taping anywhere on the screen. I don't have my interface done programmatically, I just used the interface builder to place the labels for things on the screen.

How can I use a tap gesture to change the alpha of a specific UILabel in my program?

Thanks in advance!

like image 333
Donavon Yelton Avatar asked Jul 14 '11 17:07

Donavon Yelton


1 Answers

In viewDidLoad:

UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [oneTap setNumberOfTapsRequired:1];
    [oneTap setNumberOfTouchesRequired:1];
    [self.view oneTap];

Then define the method:

-(void)tapAction:(UIGestureRecognizer *)gesture 
    {
          [self.yourLabel setAlpha:0.5f]; // set the alpha to whatever you want, or animate the fade, whatever
    }
like image 107
Todd Hopkinson Avatar answered Oct 27 '22 13:10

Todd Hopkinson