iOS中自动消失提示框的实现

iOS中自动消失提示框的实现

//添加一个提示框
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"你很漂亮" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alert show];
    
    //添加延迟时间为1.0秒 然后执行dismiss:方法
    [self performSelector:@selector(dismiss:) withObject:alert afterDelay:5.0];
    
    //实现dismiss方法
    - (void)dismiss:(UIAlertView *)alert
    {
        //此处相当于5秒之后自动点了cancel按钮
        [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
    }

  
    //声明一个label对象
    UILabel *tiplabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 225, 120, 30)];
    //设置提示内容
    [tiplabel setText:@"你好"];
    tiplabel.backgroundColor = [UIColor blackColor];
    tiplabel.layer.cornerRadius=5;
    tiplabel.layer.masksToBounds = YES;
    tiplabel.textAlignment = NSTextAlignmentCenter;
    tiplabel.textColor = [UIColor whiteColor];
    [self.view addSubview:tiplabel];
    
    //设置时间和动画效果
    [UIView animateWithDuration:10.0 animations:^{
        tiplabel.alpha =0.0;
    } completion:^(BOOL finished) {
        //
        [tiplabel removeFromSuperview];
    }];
    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值