EarlGrey
EarlGrey

Reputation: 2543

display text, then let it disappear after a minute

I'd like to display a short warning message in an existing UILabel and then have it automatically disappear after a minute or so without having to pause the app (as in doing a loop or similar).

What's the best approach ?

Upvotes: 4

Views: 2469

Answers (3)

SaKKo sama
SaKKo sama

Reputation: 61

I wrote this myself. It's pretty simple and it's probably what you are looking for. Popup any UIView instance on top or bottom then disappear after a few seconds.

https://github.com/SaKKo/SKTipAlertView

Hope you find it useful. cheers,

Upvotes: 1

Luke
Luke

Reputation: 7210

Use an NSTimer:

NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(hideLabel) userInfo:nil repeats:NO]; 

And have a method hideLabel that hides the label, with [myLabel setHidden:YES]; or something like that.

Upvotes: 4

Legolas
Legolas

Reputation: 12325

Use UIAlertView (with no buttons) for popping up something interesting.

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title"
           message:@""
             delegate:self
          cancelButtonTitle:@""
          otherButtonTitles:nil];
[alertView show];
[alertView release];

Create an method for dismissing alertView after (say 2 seconds)

[self performSelector:@selector(byeAlertView:) withObject:alertView afterDelay:2];

Method for dismissing it...

-(void)byeAlertView:(UIAlertView *)alertView{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}

Upvotes: -1

Related Questions