这篇文章主要介绍了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中如何实现弹框”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。