开发者

How to change the alpha of a UILabel by tapping?

开发者 https://www.devze.com 2023-03-20 04:17 出处:网络
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 u

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号