如何通过点击更改UILabel的alpha?

时间:2011-07-14 17:05:29

标签: iphone ios uilabel alpha

我有一个iOS(4.0)应用程序,我想通过在屏幕上的任何位置录制来更改特定UILabel的alpha。我没有以编程方式完成界面,我只是使用界面构建器在屏幕上放置标签。

如何使用点击手势更改程序中特定UILabel的alpha值?

提前致谢!

2 个答案:

答案 0 :(得分:4)

在viewDidLoad中:

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

然后定义方法:

-(void)tapAction:(UIGestureRecognizer *)gesture 
    {
          [self.yourLabel setAlpha:0.5f]; // set the alpha to whatever you want, or animate the fade, whatever
    }

答案 1 :(得分:-1)

-(IBAction)myPressedButton:(id)sender { 
    float x;
    x = theLabel.alpha;
    foat a=0.1;
    self.theLabel.alpha = x-a;
}