UIAlertView、UISheetView_前进的火车_新浪博客


一、1.创建警告框的实例

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title"

  message:@"message" delegate:nil cancelButtonTitle:@"NO" 

  otherButtonTitles:@"YES",nil]; 

2.设置警告框的代理对象,当用户对alertView有任何操作时,都会交给代理对象来进行响应

alert.delegate = self;

3.设置警告框的显示样式(共4种)

alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

 

UITextField *textField = [alertView textFieldAtIndex:0];

设置警告框的样式

alertViewStyle属性:

1.UIAlertViewStyleDefault = 0默认

2.UIAlertViewStyleSecureTextInput    只有一个文本框且是密码框

3.UIAlertViewStylePlainTextInput     只有一个普通的文本框

4.UIAlertViewStyleLoginAndPasswordInput  有两个文本框,一个用户名,一个密码框


4.显示警告框

[alert show]; 

5.成为委托方代理需遵循协议<</span>UIAlertViewDelegate>,协议中方法有:

- (void)alertView:(UIAlertView *)alertView

     clickeonAtIndex:(NSInteger)buttonIndex; //点击按钮携带文本框信息

- (void)alertViewCancel:(UIAlertView *)alertView;//点击cancel按钮

- (void)willPresentAlertView:(UIAlertView *)alertView;//警告框即将展现

- (void)didPresentAlertView:(UIAlertView *)alertView;//警告框已经展现

- (void)alertView:(UIAlertView *)alertView

     willDismissWithButtonIndex:(NSInteger)buttonIndex;//文本框即将消失

- (void)alertView:(UIAlertView *)alertView

     didDismissWithButtonIndex:(NSInteger)buttonIndex;//文本框已经消失 

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;//


二、1.创建操作表

UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"title"

  delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"危险" 

  otherButtonTitles:@"微博",@"微信",@"朋友圈", nil]; 

2.显示操作表

[sheet showInView:self.view];

3.操作表遵循的协议<</span>UIActionSheetDelegate>中的方法:

- (void)actionSheet:(UIActionSheet *)actionSheet  

     clickeonAtIndex:(NSInteger)buttonIndex;

- (void)actionSheetCancel:(UIActionSheet *)actionSheet;

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet;

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet;

- (void)actionSheet:(UIActionSheet *)actionSheet  

     willDismissWithButtonIndex:(NSInteger)buttonIndex;

- (void)actionSheet:(UIActionSheet *)actionSheet  

     didDismissWithButtonIndex:(NSInteger)buttonIndex;

4.在actionSheet中可以根据选中的按钮索引,获取按钮上的文字标题

NSString *selectedTitle = [actionSheet buttonTitleAtIndex:buttonIndex];

if ([selectedTitle isEqualToString:@"危险"]) {

  NSLog(@"点击了危险按钮");




注意:此方法库iOS8以后的方法

1.UIAlertController 1.创建2.设置3.添加4.显示

  step1:创建控制器实例

  UIAlertController *alertController =

   [UIAlertController alertControllerWithTitle:@"Title"

   message:@"messsage"

   preferredStyle:UIAlertControllerStyleAlert];



  UIAlertAction *cancelAction =

   [UIAlertAction actionWithTitle:@"取消"

   style: UIAlertActionStyleCancel

  handler:^(UIAlertAction *action) { }];

  [alertController addAction:cancelAction];


  [alertController addTextFieldWithConfigurationHandler:

   ^(UITextField *textField) {

        textField.secureTextEntry = YES;

    }];


  [self presentViewController:alertController

   animated:YES completion:nil];

























  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值