实现渐渐消失的提示框

主要参考了:http://www.oschina.net/code/snippet_1771722_44835 的内容。

#pragma mark 以渐渐消失的方式显示信息

-(void)showMessage:(NSString *)message

{

    //This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible message.

    //保持最近发送makeKeyAndVisible信息的window,即正在显示的窗口

    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    UIView *showView = [[UIView alloc]init];

    showView.backgroundColor = [UIColor blackColor];

    //先占位

    showView.frame = CGRectMake(1, 1, 1, 1);

    showView.layer.cornerRadius = 10.0f;

    showView.layer.masksToBounds = YES;

    [window addSubview:showView];

    

    UILabel *_label = [[UILabel alloc]init];

    

    UIFont *font = [UIFont boldSystemFontOfSize:15];

    _label.font = font;

    

    CGSize labelSize = [message sizeWithAttributes:@{NSFontAttributeName:font}];

    

    _label.frame = CGRectMake(10, 5, labelSize.width, labelSize.height);

    _label.text = message;

    _label.textColor = [UIColor whiteColor];

    _label.textAlignment = NSTextAlignmentCenter;

    _label.backgroundColor = [UIColor clearColor];

    

    [showView addSubview:_label];

    

//    showView.clipsToBounds = YES;

    

    showView.frame = CGRectMake((SCREEN_WIDTH - labelSize.width - 20)/2, SCREEN_HEIGHT - 240, labelSize.width + 10, labelSize.height + 10);

    

    [UIView animateWithDuration:3 animations:^{

        showView.alpha = 0;

    } completion:^(BOOL finished) {

        [showView removeFromSuperview];

    }];

}

效果如下所示:




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值