UIAlertView,UIActionSheet的使用

UIAlertView

主要功能:用于提示用户相关信息,并与用户进行交互,比如给用户提供选择或确认。
UILertView常用属性和初始化放法
UIAlertViewStyle *alertViewStyle
      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

主要功能:主要是从屏幕下方弹出提示信息提示用户
UIActionSheet常用属性和初始化方法
//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;

UIActionSheet代码展示
@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;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值