iOS提示弹窗

 1 +(void)showMessage:(NSString *)message
 2 {
 3     UIWindow * window = [UIApplication sharedApplication].keyWindow;
 4     UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KscreenWidth, KscreenHeigh)];
 5     view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
 6     [window addSubview:view];
 7     CGRect message_rect = [message boundingRectWithSize:CGSizeMake(window.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}  context:nil];
 8     
 9     UIView *showview =  [[UIView alloc]init];
10     showview.backgroundColor = [UIColor whiteColor];
11     showview.frame = CGRectMake((window.frame.size.width-message_rect.size.width)/2, (window.frame.size.height-SCREEN_HEIGHT)/2, message_rect.size.width, SCREEN_HEIGHT);
12     showview.alpha = 1.0f;
13     showview.layer.cornerRadius = 5.0f;
14     showview.layer.masksToBounds = YES;
15     [window addSubview:showview];
16     
17     UILabel *label = [[
18                        UILabel alloc]init];
19     label.frame = CGRectMake(0, 0, message_rect.size.width, SCREEN_HEIGHT);
20     label.text = message;
21     label.textColor = [UIColor blackColor];
22     label.numberOfLines = 0;
23     label.textAlignment = 1;
24     label.backgroundColor = [UIColor clearColor];
25     label.font = [UIFont systemFontOfSize:15];
26     [showview addSubview:label];
27 
28     [UIView animateWithDuration:2 animations:^{
29         showview.alpha = 0;
30         view.alpha = 0;
31     } completion:^(BOOL finished) {
32         [showview removeFromSuperview];
33         [view removeFromSuperview];
34     }];
35 }
原文地址:https://www.cnblogs.com/kfgcs/p/6387572.html