使UILabel消失

时间:2014-04-05 14:55:47

标签: ios objective-c uilabel

我正在开发一个儿童应用程序,需要在几秒钟后让答案消失 我需要添加什么?

- (IBAction)calculate2:(id)sender
{     
    float aaaa = 6;     
    Answer2.text = [ [NSString alloc] initWithFormat:@"%.0f ",aaaa];      
}

3 个答案:

答案 0 :(得分:0)

-(void) hideLabel
{
      [Answer2 setHidden:YES];
}

只需将[self performSelector:@selector(hideLabel) withObject:nil afterDelay:4]添加到calculate2

即可

答案 1 :(得分:0)

为了隐藏它非动画,它将是:

[label setHidden:YES];

但如果你想用动画隐藏它,可能是:

[UIView animatedwithduration:1.0f delay:.35f animations:{

label.alpha = 0.0;


}completion:{
[label removeFromSuperview];
//Here you can put a completed code
}];

希望它有所帮助!

答案 2 :(得分:0)

使用NSTimer并提及UILabel指定的时间消失:

- (IBAction)calculate2:(id)sender
{     
    float aaaa = 6;     
    Answer2.text = [[NSString alloc] initWithFormat:@"%.0f ",aaaa];

    [NSTimer scheduledTimerWithTimeInterval:2.0
                                     target:self
                                   selector:@selector(targetMethod:)
                                   userInfo:nil
                                    repeats:NO];
}

-(void)targetMethod:(NSTimer*)timer
{
    //toggle hidden parameter
    [Answer2 setHidden:!Answer2.hidden];
}