UI-UIAlertView

#pragma mark - 1.基本用法
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Test" message:@"显示内容" delegate: nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    [alertView show];

#pragma mark - 2.多个按钮
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Test2" message:@"message" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"其他", nil];
    [alertView show];
    


#pragma mark - 3.一些系统样式参数
    /*
     UIAlertViewStyle这个枚举提供了几个样式
     
     1 typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
     2 UIAlertViewStyleDefault = 0,           缺省样式
     3 UIAlertViewStyleSecureTextInput,        密文输入框
     4 UIAlertViewStylePlainTextInput,         明文输入框
     5 UIAlertViewStyleLoginAndPasswordInput     登录用输入框,有明文用户名,和密文密码输入二个输入框
        }
     */
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
    [alertView show];
    [alertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];


#pragma mark - 4. 判断用户点击了哪个按钮
首先遵守协议

@interface AppDelegate ()<UIAlertViewDelegate>

@end

方法:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{   //判断点击了哪个按钮
    NSLog(@"%ld",buttonIndex);
    //如果是有输入框的
    if (buttonIndex == 1) {
         NSLog(@"Login = %@",[alertView textFieldAtIndex:0].text);
         NSLog(@"PassWorld = %@",[alertView textFieldAtIndex:1].text);
    }else{
        NSLog(@"退出");
    }
    
    
}
- (void)buttonpressed{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Test" message:@"显示内容" delegate: self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    [alertView show];
    [alertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
}

实现代码:(点击button触发 )

    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(0, 0, 200, 30);
    button.center = CGPointMake(_window.frame.size.width/2, _window.frame.size.height/2);
    [button setTitle:@"button" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonpressed) forControlEvents:UIControlEventTouchUpInside];
    [_window addSubview:button];

#pragma mark - 5.添加子视图(IOS7不能添加子视图了)
//         UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"请等待"
//                                                                                  message:nil
//                                                                                 delegate:nil
//                                                                        cancelButtonTitle:nil
//                                                                        otherButtonTitles:nil,
//                                                                                          nil];
//    
//         UIActivityIndicatorView *activeView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
//         activeView.center = CGPointMake(view.bounds.size.width/2.0f, view.bounds.size.height-40.0f);
//         [activeView startAnimating];
//         [view addSubview:activeView];
//    
//         [view show];


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值