Chinaunix

标题: 在iOS中实现类似安卓自动消失提示框 [打印本页]

作者: zzfh    时间: 2015-06-24 10:23
标题: 在iOS中实现类似安卓自动消失提示框
转载搬运。
  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. }
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2