iOS开篇——UI之UAlertView(提示框)

创建提示框

 //创建提示框
    //标题  提示内容  代理对象  按钮

    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"警告" message:@"萨达姆已经做好战斗准备" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"不确定", nil];

设置提示框样式

    alertView .alertViewStyle = UIAlertViewStylePlainTextInput;
    /*
     typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
     UIAlertViewStyleDefault = 0,
     UIAlertViewStyleSecureTextInput,   密文输入
     UIAlertViewStylePlainTextInput,    明文输入
     UIAlertViewStyleLoginAndPasswordInput  明文+密文
     } __TVOS_PROHIBITED;
     */

让alertView显示出来

[alertView show];

设置代理 实现协议方法

alertView.delegate = self;
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        NSLog(@"点击了取消");
        NSLog(@"%@",[alertView textFieldAtIndex:0].text);
    }else{
        NSLog(@"点击了确定");
    }
}

iOS9之后不建议使用

UIAlertController+UIAlertControllerStyleAlert 也可以实现同样功能

时间: 2024-08-07 20:53:09

iOS开篇——UI之UAlertView(提示框)的相关文章

iOS - UIAlertController三种显示提示框代码

UIAlertView在IOS 8以上版本已经过时了,官方推荐我们使用UIAlertController代替UIAlertView.UIActionSheet 1?UIAlertController显示普通的Alert - (IBAction)showAlert:(UIButton *)sender { //显示提示框 //过时 // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@&q

iOS开篇——UI之UITableView

1 #import "ViewController.h" 2 3 @interface ViewController ()<UITableViewDataSource,UITableViewDelegate> 4 { 5 //创建数据源 6 NSMutableArray * _dataArray; 7 8 } 9 10 @end 11 12 @implementation ViewController 13 14 - (void)viewDidLoad { 15 [supe

iOS 用户允许定位权限提示框闪现

需要访问用户位置的应用,在第一次启动时应该弹出 允许"xx"在您使用该应用时访问您的位置 或者 一直访问位置的提示框. 在开发中,我遇到这个提示框闪现的问题,原因是我使用了arc. 开始我在delegate  didFinishLaunchingWithOptions中这样写的 //地图定位 CLLocationManager * locationManager = [[CLLocationManager alloc] init]; if ([[UIDevice currentDevi

iOS学习笔记--01swift实现提示框第三方库:MBProgressHUD

本文使用swift语言使用MBProgressHUD. 开源项目MBProgressHUD可以实现多种形式的提示框.使用简单,方便. GitHud的下载地址是:https://github.com/jdg/MBProgressHUD/ 下载完成后,将MBProgressHUD.h和MBProgressHUD.m拖入已经新建好的Swift项目.因为使用的swift语言,所以拖入项目的时候会提示是否新建一个桥接objective-c与swift的文件,选择是即可.此步骤会自动新建一个文件.如图: 在

iOS开篇——UI之UITextField

创建文本输入框 UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 250, 40)]; 设置边框样式 textField.borderStyle = UITextBorderStyleRoundedRect; /* typedef NS_ENUM(NSInteger, UITextBorderStyle) { UITextBorderStyleNone, 无效果 UITextBorderS

iOS开篇——UI之UIGestureRecogzier_手势

一.UITouch 1 //任何视图都可以触发此方法 2 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 3 NSLog(@"视图被触摸了"); 4 } 5 6 - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ 7 NSLog(@"因意外

iOS开篇——UI之UITextView

创建UITextView //创建一个单例对象 存储_str字符串 NSUserDefaults * hd = [NSUserDefaults standardUserDefaults]; _str = [hd objectForKey:@"str"]; UITextView * textView = [[UITextView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)]; textView.delegate = self; te

iOS开篇——UI之UISegmentedControl (分段选择器)

创建分段选择器 UISegmentedControl * sc = [[UISegmentedControl alloc]initWithFrame:CGRectMake(50, 100, 200, 30)]; [sc insertSegmentWithTitle:@"第一页" atIndex:0 animated:YES]; [sc insertSegmentWithTitle:@"第二页" atIndex:1 animated:YES]; [sc insertS

iOS开篇——UI之UIActionSheet

UIActionSheet在iOS8.3之后已不建议使用. 可以使用 UIAlertController+UIAlertControllerStyleActionSheet获得同样的效果 创建UIActionSheet UIActionSheet * as = [[UIActionSheet alloc]initWithTitle:@"选择一个英雄" delegate:self cancelButtonTitle:@"取消" destructiveButtonTit