IOS之弹框的实现方法
来源:爱站网时间:2019-10-21编辑:网友分享
我们在开发项目的时候,都需要要弹框的提示,但是弹框的实现方式要在IOS中如何实现呢?别着急,今天就跟着爱站技术频道小编的步伐来了解IOS之弹框的实现方法。
我们在开发项目的时候,都需要要弹框的提示,但是弹框的实现方式要在IOS中如何实现呢?别着急,今天就跟着爱站技术频道小编的步伐来了解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之绘制三角形的实例讲解
