取消了UIAlertView代替的是UIAlertController。
// UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册" message:@"注册之前请先充钱" preferredStyle:(UIAlertControllerStyleActionSheet)];区别是,个个是出现在最下面,并且当中有空格
// UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册" message:@"注册之前请先充钱" preferredStyle:(UIAlertControllerStyleAlert)];//这个事连接的
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册" message:@"注册之前请先充钱" preferredStyle:(UIAlertControllerStyleAlert)];
//这个则是出现在中间,并且中间只有一丝横线做为空隙,这个是出现提示的方式及要显示的字,title则是主题,另一个则是主题之后的message,就是提示信息;
[alert addAction:[UIAlertAction actionWithTitle:@"充值" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"充值成功");//这个就是点击之后会跳到原页面,要想点击之后还在原界面,得添加,和默认的区别就在于字体的颜色和深度上
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"充值成功可以注册");
}];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"我再考虑考虑" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"考虑毛线");//这个就是点击之后会跳到原页面
[self presentViewController:alert animated:YES completion:NULL];
}]];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// 可以在这里对textfield进行定制,例如改变背景色
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextFieldTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:textField];
textField.secureTextEntry = YES;
textField.backgroundColor = [UIColor whiteColor];
//这是在alert里面添加输入时加入的,用通知结束的时候记得移除通知
}];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
exit(0);//这个是红色字因为退出什么的警告需要用到
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:alert.textFields.firstObject];//移除
}]];
[self presentViewController:alert animated:YES completion:NULL];
[self dismissViewControllerAnimated:YES completion:NULL];//是否取消,后面的是消失前发送什么
// self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;//这个动画效果是反转
self.modalTransitionStyle = 0;//默认下拉
//UIModalTransitionStyleCrossDissolve;//直接一闪