首页 > 代码库 > ios8 UIAlertController

ios8 UIAlertController

ios8 上面,用UIAlertController将UIAlertView和UIActionSheet合二为一了。 

(1)创建普通alert

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title  message:message  preferredStyle:UIAlertControllerStyleAlert];        // Create the actions.    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle  style:UIAlertActionStyleCancel  handler:^(UIAlertAction *action) {        NSLog(@"The \"Okay/Cancel\" alert‘s cancel action occured.");    }];        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle  style:UIAlertActionStyleDefault  handler:^(UIAlertAction *action) {        NSLog(@"The \"Okay/Cancel\" alert‘s other action occured.");    }];        // Add the actions.    [alertController addAction:cancelAction];    [alertController addAction:otherAction];        [self presentViewController:alertController animated:YES completion:nil];

如果UIAlertAction *otherAction这种otherAction多几个的话,它会自动排列成一列。

(2)带有输入框的alert

如果需要在 alertview上面添加输入框等,如下:
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {        // 可以在这里对textfield进行定制,例如改变背景色        textField.backgroundColor = [UIColor orangeColor];    }];

ios8 UIAlertController