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

后端 未结 10 994
孤城傲影
孤城傲影 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 12:04

    I ended up creating my own class. Didn't inherit from UIAlertView. General structure is,

    -(id)initWithText:(NSString *)msg {
        // Create a view. Put a label, set the msg
        CALayer *layer = self.layer;
        layer.cornerRadius = 8.0f;
        ...
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.8];
        [self performSelector:@selector(dismiss:) withObject:nil afterDelay:2.0];
        [self setAutoresizesSubviews:FALSE];
        return self;
    }
    
    
    - (void)dismiss:(id)sender {
        // Fade out the message and destroy self
        [UIView animateWithDuration:0.5 
                     animations:^  { self.alpha = 0; }
                     completion:^ (BOOL finished) { [self removeFromSuperview]; }];
    }
    

提交回复
热议问题