温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

IOS中如何实现弹框

发布时间:2021-07-08 14:32:16 来源:亿速云 阅读:127 作者:小新 栏目:移动开发

这篇文章主要介绍了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中如何实现弹框”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节
推荐阅读:
  1. js选择弹框
  2. layer弹框

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios
AI