您的位置:首页 > 移动开发 > IOS开发

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

2016-08-26 17:48 316 查看
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];
}];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息