这篇文章主要介绍了IOS 中弹框的实现方法整理的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
IOS 中弹框的实现方法整理
#define iOS8Later ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0)
ios 8以前的弹框
@interface RootViewController ()<UIAlertViewDelegate>
@end
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"登陆失败" message:@"请重新输入用户名和密码" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
#pragma mark - UIAlertView Delegate Methods -
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
NSLog(@"点击取消按钮后,想要的操作,可以加此处");
}
else if(buttonIndex == 1)
{
NSLog(@"点击确定按钮后,想要的操作,可以加此处");
}
}
ios8以后的弹框
UIAlertController *_alertVC = [UIAlertController alertControllerWithTitle:@"登陆失败" message:@"请重新输入用户名和密码" preferredStyle:UIAlertControllerStyleAlert];
//警告类型,红色字体 UIAlertActionStyleDestructive
// UIAlertAction *_doAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
// [_alertVC addAction:_doAction];
UIAlertAction *_doAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action)
{
NSLog(@"点击确定按钮后,想要的操作,可以加此处");
}];
[_alertVC addAction:_doAction];
// UIAlertAction *_cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
// [_alertVC addAction:_cancleAction];
UIAlertAction *_cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action)
{
NSLog(@"点击取消按钮后,想要的操作");
}];
[_alertVC addAction:_cancleAction];
[self presentViewController:_alertVC animated:YES completion:nil];
//警告类型,红色字体 UIAlertActionStyleDestructive,如下图所示的效果
UIAlertAction *_doAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
[_alertVC addAction:_doAction];

如有疑问请留言或者到本站社区交流讨论,希望通过本文能帮助到大家,谢谢大家对本站的支持!
织梦狗教程
本文标题为:IOS 中弹框的实现方法整理
基础教程推荐
猜你喜欢
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Flutter手势密码的实现示例(附demo) 2023-04-11
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- android studio按钮监听的5种方法实例详解 2023-01-12
- Android多返回栈技术 2023-04-15
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- Android中的webview监听每次URL变化实例 2023-01-23
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- iOS开发教程之XLForm的基本使用方法 2023-05-01
