栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > iOS

IOS 中弹框的实现方法整理

iOS 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

IOS 中弹框的实现方法整理

IOS 中弹框的实现方法整理

#define iOS8Later ([UIDevice currentDevice].systemVersion.doublevalue >= 8.0)

ios 8以前的弹框

@interface RootViewController () 
 
@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];

如有疑问请留言或者到本站社区交流讨论,希望通过本文能帮助到大家,谢谢大家对本站的支持!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/166514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号