UIAlertController+Extend.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // UIAlertController+Extend.m
  3. // IDCardRecognition
  4. //
  5. // Created by zhongfeng1 on 2017/3/6.
  6. // Copyright © 2017年 李中峰. All rights reserved.
  7. //
  8. #import "UIAlertController+Extend.h"
  9. @implementation UIAlertController (Extend)
  10. +(instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle okAction:(UIAlertAction *)okAction cancelAction:(UIAlertAction *)cancelAction {
  11. UIAlertController *alertC = [self alertControllerWithTitle:title message:message preferredStyle:preferredStyle];
  12. // 两个action("确定"、“取消”)依添加顺序从左至右排列
  13. if (cancelAction) {
  14. [alertC addAction:cancelAction];
  15. }
  16. if (okAction) {
  17. [alertC addAction:okAction];
  18. }
  19. return alertC;
  20. }
  21. +(instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message okAction:(UIAlertAction *)okAction cancelAction:(UIAlertAction *)cancelAction {
  22. return [self alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert okAction:okAction cancelAction:cancelAction];
  23. }
  24. +(instancetype)actionSheetControllerWithTitle:(NSString *)title message:(NSString *)message okAction:(UIAlertAction *)okAction cancelAction:(UIAlertAction *)cancelAction {
  25. return [self alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet okAction:okAction cancelAction:cancelAction];
  26. }
  27. @end