BlockAlertController.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // BlockAlertController.m
  3. // MIT_Endorsement
  4. //
  5. // Created by 翟玉磊 on 2018/4/2.
  6. // Copyright © 2018年 翟玉磊. All rights reserved.
  7. //
  8. #import "BlockAlertController.h"
  9. @implementation BlockAlertController
  10. + (UIAlertController *)actionSheetWithTitle:(NSString *)title message:(NSString *)message actionTitles:(NSArray *)titles cancelTitle:(NSString *)cancelTitle clickAction:(void (^)(UIAlertAction *))completion
  11. {
  12. UIAlertController *al = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
  13. for (NSString *name in titles) {
  14. UIAlertAction *action = [UIAlertAction actionWithTitle:name style:UIAlertActionStyleDefault handler:completion];
  15. [al addAction:action];
  16. }
  17. if ([BaseMethod isNOTNull:cancelTitle]) {
  18. UIAlertAction *cancel = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:completion];
  19. [al addAction:cancel];
  20. }
  21. return al;
  22. }
  23. + (UIAlertController *)alertWithTitle:(NSString *)title message:(NSString *)message cancelTitle:(nonnull NSString *)cancelTitle sureTitle:(NSString *)sureTitle clickAction:(void (^)(UIAlertAction *))completion
  24. {
  25. UIAlertController *al = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  26. UIAlertAction *action = [UIAlertAction actionWithTitle:sureTitle style:UIAlertActionStyleDefault handler:completion];
  27. [al addAction:action];
  28. if ([BaseMethod isNOTNull:cancelTitle]) {
  29. UIAlertAction *cancel = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:completion];
  30. [al addAction:cancel];
  31. }
  32. return al;
  33. }
  34. + (UIAlertController *)alertWithTitle:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle cancelTitleColor:(UIColor *)cancelTitleColor sureTitle:(NSString *)sureTitle sureTitleColor:(UIColor *)sureTitleColor clickAction:(void (^)(UIAlertAction *))completion {
  35. UIAlertController *al = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  36. if ([BaseMethod isNOTNull:cancelTitle]) {
  37. UIAlertAction *cancel = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleDefault handler:completion];
  38. if (cancelTitleColor) {
  39. [cancel setValue:cancelTitleColor forKey:@"_titleTextColor"];
  40. }
  41. [al addAction:cancel];
  42. }
  43. UIAlertAction *action = [UIAlertAction actionWithTitle:sureTitle style:UIAlertActionStyleDefault handler:completion];
  44. if (sureTitleColor) {
  45. [action setValue:sureTitleColor forKey:@"_titleTextColor"];
  46. }
  47. [al addAction:action];
  48. return al;
  49. }
  50. @end