免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1768 | 回复: 0
打印 上一主题 下一主题

[iOS] 在iOS中实现类似安卓自动消失提示框 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-06-24 10:23 |只看该作者 |倒序浏览
转载搬运。
  1. +(void)showMessage:(NSString *)message
  2. {
  3.     UIWindow * window = [UIApplication sharedApplication].keyWindow;
  4.     UIView *showview =  [[UIView alloc]init];
  5.     showview.backgroundColor = [UIColor blackColor];
  6.     showview.frame = CGRectMake(1, 1, 1, 1);
  7.     showview.alpha = 1.0f;
  8.     showview.layer.cornerRadius = 5.0f;
  9.     showview.layer.masksToBounds = YES;
  10.     [window addSubview:showview];
  11.      
  12.     UILabel *label = [[UILabel alloc]init];
  13.     CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)];
  14.     label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height);
  15.     label.text = message;
  16.     label.textColor = [UIColor whiteColor];
  17.     label.textAlignment = 1;
  18.     label.backgroundColor = [UIColor clearColor];
  19.     label.font = [UIFont boldSystemFontOfSize:15];
  20.     [showview addSubview:label];
  21.     showview.frame = CGRectMake((SCREEN_WIDTH - LabelSize.width - 20)/2, SCREEN_HEIGHT - 100, LabelSize.width+20, LabelSize.height+10);
  22.     [UIView animateWithDuration:1.5 animations:^{
  23.         showview.alpha = 0;
  24.     } completion:^(BOOL finished) {
  25.         [showview removeFromSuperview];
  26.     }];
  27. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP