IOS 提示框UIAlertView,UIActionSheet,UIAlertController

一:UIAlertView警告框 IOS 2 - IOS 9

UIAlertView*AlertView=[[UIAlertView alloc]initWithTitle:@"请给我们一个评价" message:@"我们很尽力的去做一个应用,请给我们一个评价" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];

[AlertView show];//展示出来

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

触摸屏幕调用这个函数

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

选择按键后调用函数。

NSLog(@"我们选择了那一个按键%d",buttonIndex);

}

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

{

警告消失后调用函数。

NSLog(@"已经消失,按键是哪一个");

}

-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

{

NSLog(@"即将消失,按键是那一个");

}

-(void)alertViewCancel:(UIAlertView *)alertView

{

点击取消键调用函数

NSLog(@"点取消按键");

}

二:UIActionSheet从下面弹出来的提示框,IOS 2 - IOS 8.3

遵从 UIActionSheetDelegate协议

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

UIActionSheet*ActionSheet=[[UIActionSheet alloc]initWithTitle:@"资源名" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"你猜" otherButtonTitles:@"你在猜", nil];

[ActionSheet showInView:self.view];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

NSLog(@"点击了哪个");

}

三:UIAlertController,继承自UIViewController,用以替代UIAlertView和UIActionSheet,IOS 8开始。

实例化方法为+ (instancetype)alertControllerWithTitle:(nullableNSString*)title message:(nullableNSString*)message preferredStyle:(UIAlertControllerStyle)preferredStyle;

typedefNS_ENUM(NSInteger, UIAlertControllerStyle) {

UIAlertControllerStyleActionSheet =0,

UIAlertControllerStyleAlert

}NS_ENUM_AVAILABLE_IOS(8_0);对应alert和action两种样式。

通过- (void)addAction:(UIAlertAction*)action;来添加按钮项。

在项目中,可以创建一个alert管理类,来管理整个项目中的弹出框。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 代码下载地址一代码下载地址二 前言 在iOS应用程序中,我们经常看到各种各样的弹出框,比如地理信息、相册、相机、权...
    酒茶白开水阅读 25,877评论 11 28
  • 大纲 一、UIAlertView项目:UIAlertView0314步骤: 1.创建AlertView 2.实现可...
    AsaGuo阅读 3,265评论 0 0
  • { 11、核心动画 需要签协议,但是系统帮签好 一、CABasicAnimation 1、创建基础动画对象 CAB...
    CYC666阅读 5,480评论 2 4
  • UIAlertController(iOS8)是 UIAlertView和UIActionSheet替代和升级版。...
    iOS_SXH阅读 5,515评论 0 0
  • 昨天我的老朋友苏在我的一篇文章下评论道:“你才是正能量满满啊!心底阳光的人,看满世界都灿烂。”我看了觉得很感动,很...
    繁花落尽深眸阅读 4,212评论 10 12