1.UIAlertViewStyleDefault = 0;//默认
2.UIAlertViewStyleSecureTextInput;//密码风格,也就是输入内容不回现
3.UIAlertViewStylePlainTextInput;//文本输入风格,可以看到输入的内容
4.UIAlertViewStyleLoginAndPasswordInput;//登陆风格的弹出框
id/ * <UIAlertViewDelegate> * / delegate;//UIAlertView的委托
- (id)initWithTitle:(NSString*)title message:( NSString *)message delegate:(id/*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles,...
- (void)show;//展示UIAlertView
//UIAlertView的委托方法之一,主要作用是当用户与UIAlertView进行交互是,所触发的动作
- (Void)alertView:(UIAlterView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
实例:
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:
@"警告" message:
@"你的用户名或者密码有误,请根据实际情况来确认详细信息,并进行再次操作" delegate:self cancelButtonTitle:
@"取消" otherButtonTitles:
@"确认", nil];
// 用于真正来展示alerView
// alerView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
// alerView.alertViewStyle = UIAlertViewStylePlainTextInput;
alerView.alertViewStyle = UIAlertViewStyleSecureTextInput;
[alerView show];
//UIActionSheet的初始化方法,需要注意一下各个参数在现实的时候的位置
- (id)initWithTitle:(NSStirng *)title delegate:
(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString*)destructiveButtonTitle otherButtonTitle:(NSString *)otherButtonTitles,...
//在指定视图下方现实UIActionSheet视图
- (void)showInView:(UIView *)view;
//UIActionSheet的主要委托方法,作用是当用户与UIActionSheet进行交互的时候,捕获所触发的动作。
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
@interface ViewController ()<UIActionSheetDelegate>
//delegate:self时,ViewController就要遵守UIActionSheet的协议:UIActionSheetDelegate
- (IBAction)onButton:(id)sender forEvent:(UIEvent *)event {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"警告" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确认" otherButtonTitles:@"hahah", nil];
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%ld",buttonIndex);
switch (buttonIndex) {
case 0:
NSLog(@"用户点击了确认按钮");
break;
case 1:
NSLog(@"用户点击了hello");break;
case 2:
NSLog(@"用户点击了取消按钮");break;
default:
break;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wow09_1225/article/details/46757877