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!
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
}
-(IBAction)myPressedButton:(id)sender {
float x;
x = theLabel.alpha;
foat a=0.1;
self.theLabel.alpha = x-a;
}
精彩评论