UIAlertController 总结

UIAlertControllerStyleAlert模式

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"message" message:@"what is fine" preferredStyle:UIAlertControllerStyleActionSheet];
    
     UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancle" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];
    
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
       
    }];

    [alertVC addAction:cancel];
    [alertVC addAction:sure];
  
    //展示
    [self presentViewController:alertVC animated:YES completion:nil];

}
UIAlertController 总结_第1张图片
UIAlertControllerStyleAlert模式

)

UIAlertControllerStyleActionSheet模式

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"message" message:@"what is fine" preferredStyle:UIAlertControllerStyleActionSheet];
    
     UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancle" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];
    
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
       
    }];

    [alertVC addAction:cancel];
    [alertVC addAction:sure];
  
    //展示
    [self presentViewController:alertVC animated:YES completion:nil];

}
UIAlertController 总结_第2张图片
UIAlertControllerStyleActionSheet样式

UIAlertAction style样式

    typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
        UIAlertActionStyleDefault = 0, // 按钮标准样式
        UIAlertActionStyleCancel, // 按钮取消样式
        UIAlertActionStyleDestructive // 按钮警示性样式
    } NS_ENUM_AVAILABLE_IOS(8_0);

UIAlertAction 按钮颜色多元化设置

[sure setValue:[UIColor greenColor] forKey:@"titleTextColor"];

带输入框的UIAlertControllerStyleAlert

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"message" message:@"what is fine" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancle" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        UITextField *txt = [alertVC.textFields objectAtIndex:0];
        NSLog(@"%@",txt.text);

        UITextField *txt1 = [alertVC.textFields objectAtIndex:1];
        NSLog(@"%@",txt1.text);
        
    }];
    
    [alertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入您的账号";
    }];
    
    [alertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入您的密码";
    }];
    
    [alertVC addAction:cancel];
    [alertVC addAction:sure];

    //展示
    [self presentViewController:alertVC animated:YES completion:nil];
    
}
UIAlertController 总结_第3张图片
UIAlertAction 按钮颜色多元化设置

特别注意:带输入框的UIAlertControllerStyleAlert 只能在UIAlertControllerStyleAlert 模式下设置,UIAlertControllerStyleActionSheet模式下不支持。

你可能感兴趣的:(UIAlertController 总结)