How to display temporary popup message on iPhone/iPad/iOS

I'd like to display a temporary message on the iPhone/iPad displaying confirmation of an action, or some quick status about some background activity.

Is there a standard control to do this? I've seen apps do this. A rounded rectangle, dark and partially transparent with text inside. It does not ask for user input but disappears on its own in some short period of time. Android has a similar construct which is standard. Also similar to the windows displayed by Growl.

Suggestions appreciated.


There is a user library on cocoacontrols.com that emulates the Android-style Toast pop-ups. Might be what you are looking for.

http://www.cocoacontrols.com/platforms/ios/controls/altoastview

There's also this one that follows the same idea.

http://www.cocoacontrols.com/platforms/ios/controls/itoast


Create a class that inherits from UIAlertView. In your constructor just call [super init] and then add any view you want as a subview. You can even design this view in Interface Builder. Something like this:

- (id)initWithMessage:(NSString *)message dismissAfter:(NSTimeInterval)interval
{
  if ((self = [super init]))
  {
     CustomView * customView = [[[CustomView alloc] init] autorelease]; // or load from NIB
     [self addSubview:customView];
     [self performSelector:@selector(dismissAfterDelay) withObject:nil afterDelay:interval];
  }
  return self;
}

- (void)dismissAfterDelay
{
  [self dismissWithClickedButtonIndex:0 animated:YES]; 
}

To display your custom alert view just init it, and call show as with a regular UIAlertView.

CustomAlertView * cav = [[CustomAlertView alloc] initWithMessage:@"Doing Something];
[cav show];
[cav release];

As an nice side-effect, when you present this view the background will darken and you will get the nice wobbly animation for any alert view.


Use UIAlertView. Here's a quick link to a simple example:

UIAlertView

Edited: Sorry, didn't see about disappearing on it's own. I think you need to have some confirmation by users of messages received. UIAlertView pretty much accomplishes that. Not sure if you have it gradually fade away unless you're in an app with a view that has a timer or event based delay that will show a view and then eventually remove it.

Second edit: Found a way to implement it. You can manually call the dismiss function after some set time that you've designated. (Sorry for the messy post) It would look something like this:

//Create UIAlertView alert
alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Some message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];

//After some time
[alert dismissWithClickedButtonIndex:0 animated:TRUE];