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

后端 未结 10 986
孤城傲影
孤城傲影 2020-12-04 11:31

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 st

10条回答
  •  自闭症患者
    2020-12-04 11:58

    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.

提交回复
热议问题