iOS中的弹出窗口分为UIAlertView和UIActionSheet这两种,其中前者相似于Android中的dialog,在屏幕中间弹出一个窗口;后者为在屏幕下方弹出的窗体。字体
在iOS8之后,二者由UIAlertController统一实现:ui
UIAlertView的实现--
spa
UIAlertController* ui=[UIAlertController alertControllerWithTitle:@"title" message:@"helloWorld" preferredStyle:UIAlertControllerStyleAlert];对象
----实例化一个UIAlertController对象,在这里指定样式为UIAlertView。it
UIAlertAction* cancel=[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:nilio
];class
----为该提示框添加第二个选项密码
UIAlertAction* other=[UIAlertAction actionWithTitle:@"qitade" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){im
}];样式
----为该提示框添加第三个选项
UIAlertAction* other1=[UIAlertAction actionWithTitle:@"qitade" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
}];
-----添加单个提示框的选项(字体较大的红色提示)
UIAlertAction* reset=[UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDestructive handler:nil];
//[ui addAction:reset];
[ui addAction:cancel];
[ui addAction:other];
[ui addAction:other1];
[self presentViewController:ui animated:YES completion:nil];
--------当添加两个时候,会左右排列,超出后会上下排列--------实现一个输入用户名和密码界面的dialog
UIAlertController* ui1=[UIAlertController alertControllerWithTitle:@"t提示框" message:@"请输入" preferredStyle:UIAlertControllerStyleAlert];
[ui1 addTextFieldWithConfigurationHandler:^(UITextField *text){
text.placeholder=@"用户名";//这个至关于Android的edittext的提示语
}];
[ui1 addTextFieldWithConfigurationHandler:^(UITextField* text1){
text1.placeholder=@"密码";
text1.secureTextEntry=YES;
}];
[self presentViewController:ui1 animated:YES completion:nil];