首页 > 移动平台 > 详细

iOS提示弹窗

时间:2017-03-02 16:29:36      阅读:224      评论:0      收藏:0      [点我收藏+]
 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 }

 

iOS提示弹窗

原文:http://www.cnblogs.com/kfgcs/p/6387572.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!