IOS——仿Android自动消失的小提示窗

来源:互联网 发布:骤风租赁软件 编辑:程序博客网 时间:2024/05/29 11:00

个人觉得IOS大缺点中的其中一个就是没有自动消失的小提示窗组件

很多情况下并不需要用户点击“确定”的,感觉这一点用户体验不是很好,很多时候只需要提示用户有什么情况发生就好了

废话不说,原帖地址:

http://www.oschina.net/code/snippet_1771722_44835


以防万一拷贝一份代码在此

-(void)showMessage:(NSString *)message{    UIWindow * window = [UIApplication sharedApplication].keyWindow;    UIView *showview =  [[UIView alloc]init];    showview.backgroundColor = [UIColor blackColor];    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 = [[UILabel alloc]init];    CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)];    label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height);    label.text = message;    label.textColor = [UIColor whiteColor];    label.textAlignment = 1;    label.backgroundColor = [UIColor clearColor];    label.font = [UIFont boldSystemFontOfSize:15];    [showview addSubview:label];    CGRect rect=[[UIScreen mainScreen] bounds];    showview.frame = CGRectMake((rect.size.width - LabelSize.width - 20)/2, rect.size.height - 100, LabelSize.width+20, LabelSize.height+10);    [UIView animateWithDuration:1.5 animations:^{        showview.alpha = 0;    } completion:^(BOOL finished) {        [showview removeFromSuperview];    }];}


0 0
原创粉丝点击