在iOS中实现类似安卓自动消失提示框

来源:互联网 发布:mac分销渠道设计方案 编辑:程序博客网 时间:2024/06/07 17:23
+(void)showMessage:(NSString*)message
{
    UIWindow* window = [UIApplicationsharedApplication].keyWindow;
    UIView*showview =  [[UIViewalloc]init];
    showview.backgroundColor = [UIColorblackColor];
    showview.frame = CGRectMake(1, 1, 1, 1);
    showview.alpha = 1.0f;
    showview.layer.cornerRadius = 5.0f;
    showview.layer.masksToBounds = YES;
    [window addSubview:showview];
     
    UILabel*label = [[UILabelalloc]init];
    CGSize LabelSize = [message sizeWithFont:[UIFontsystemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)];
    label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height);
    label.text = message;
    label.textColor = [UIColorwhiteColor];
    label.textAlignment = 1;
    label.backgroundColor = [UIColorclearColor];
    label.font = [UIFontboldSystemFontOfSize:15];
    [showview addSubview:label];
    showview.frame = CGRectMake((SCREEN_WIDTH - LabelSize.width - 20)/2, SCREEN_HEIGHT - 100, LabelSize.width+20, LabelSize.height+10);
    [UIViewanimateWithDuration:1.5 animations:^{
        showview.alpha = 0;
    } completion:^(BOOLfinished) {
        [showview removeFromSuperview];
    }];

}



原文地址:http://www.oschina.net/code/snippet_1771722_44835

0 0
原创粉丝点击