iOS小控件的使用
UIAlertController
UIAlertView用來給用戶展示警告信息更耻。這個類是在iOS 8.0之后出現(xiàn)的锅铅,用來替代UIActionSheet(從底部冒出) 和 UIAlertView(從中間出現(xiàn))水泉。確定了警告控制器的動作方式和style之后,使用 presentViewController:animated:completion: 方法來展示。
typedef enum UIAlertControllerStyle: NSInteger {
UIAlertControllerStyleActionSheet = 0, //提示信息從底部彈出
UIAlertControllerStyleAlert //提示信息從中間彈出
} UIAlertControllerStyle;
使用方法:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"My Alert" message:@"This is an alert" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 點(diǎn)擊該按鈕后的邏輯
}];
// 添加action
[alert addAction:defaultAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {}];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {}];
[alert addAction:cancelAction];
[alert addAction:deleteAction];
// 彈出警告框
[self presentViewController:alert animated:YES completion:nil];
UIAlertControllerStyleActionSheet
UIAlertControllerStyleAlert