要运行示例项目,首先克隆仓库,然后从示例目录运行 pod install
。
将 MOAlertControllerStyleAlert
设置为 preferredStyle。
MOAlertController *alertController = [MOAlertController alertControllerWithTitle:@"MOAlertController" message:@"This is MOAlertController." preferredStyle:MOAlertControllerStyleAlert];
MOAlertAction *action = [MOAlertAction actionWithTitle:@"Cancel" style:MOAlertActionStyleCancel handler:^(MOAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action];
MOAlertAction *action2 = [MOAlertAction actionWithTitle:@"Destructive" style:MOAlertActionStyleDestructive handler:^(MOAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action2];
MOAlertAction *action3 = [MOAlertAction actionWithTitle:@"Default" style:MOAlertActionStyleDefault handler:^(MOAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action3];
[controller presentViewControllerWithCurrentViewController:self];;
将 MOAlertControllerStyleActionSheet
设置为 defStyleult。
MOAlertController *alertController = [MOAlertController alertControllerWithTitle:@"MOAlertController" message:@"This is MOAlertController." preferredStyle:MOAlertControllerStyleActionSheet];
MOAlertAction *action = [MOAlertAction actionWithTitle:@"Cancel" style:MOAlertActionStyleCancel handler:^(MOAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action];
MOAlertAction *action2 = [MOAlertAction actionWithTitle:@"Destructive" style:MOAlertActionStyleDestructive handler:^(MOAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action2];
MOAlertAction *action3 = [MOAlertAction actionWithTitle:@"Default" style:MOAlertActionStyleDefault handler:^(MOAlertAction *action) {
//Write a code for this action.
}];
[alertController addAction:action3];
[controller presentViewControllerWithCurrentViewController:self];
如果您想取消,请使用此方法。
[controller dismissViewControllerFromCurrentViewController];
Taiki Suzuki,[email protected]
MOAlertController 提供 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。