KSPublicAlertView.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // KSPublicAlertView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/6/28.
  6. //
  7. #import "KSPublicAlertView.h"
  8. #import "UIView+Animation.h"
  9. @interface KSPublicAlertView ()
  10. @property (weak, nonatomic) IBOutlet UILabel *topTitle;
  11. @property (weak, nonatomic) IBOutlet UILabel *descLabel;
  12. @property (weak, nonatomic) IBOutlet UIButton *cancleButton;
  13. @property (weak, nonatomic) IBOutlet UIButton *sureButton;
  14. @property (nonatomic, copy) AlertCallback cancelCallback;
  15. @property (nonatomic, copy) AlertCallback sureCallback;
  16. @end
  17. @implementation KSPublicAlertView
  18. + (instancetype)shareInstanceWithTitle:(NSString *)title descMessage:(NSString *)descMsg leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle cancelAction:(AlertCallback)cancelCallback sureAction:(AlertCallback)sureCallback {
  19. KSPublicAlertView *alertView = [[[NSBundle mainBundle] loadNibNamed:@"KSPublicAlertView" owner:nil options:nil] firstObject];
  20. alertView.topTitle.text = title;
  21. alertView.descLabel.text = descMsg;
  22. [alertView.cancleButton setTitle:leftTitle forState:UIControlStateNormal];
  23. [alertView.sureButton setTitle:rightTitle forState:UIControlStateNormal];
  24. if (cancelCallback) {
  25. alertView.cancelCallback = cancelCallback;
  26. }
  27. if (sureCallback) {
  28. alertView.sureCallback = sureCallback;
  29. }
  30. [alertView showAlert];
  31. return alertView;
  32. }
  33. - (void)showAlert {
  34. [[NSObject getKeyWindow] addSubview:self];
  35. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.top.bottom.right.mas_equalTo([NSObject getKeyWindow]);
  37. }];
  38. [self setPopAnimation];
  39. }
  40. - (void)hiddenAction {
  41. [self removeFromSuperview];
  42. }
  43. - (IBAction)cancleAction:(id)sender {
  44. if (self.cancelCallback) {
  45. self.cancelCallback();
  46. }
  47. [self hiddenAction];
  48. }
  49. - (IBAction)sureAction:(id)sender {
  50. if (self.sureCallback) {
  51. self.sureCallback();
  52. }
  53. [self hiddenAction];
  54. }
  55. /*
  56. // Only override drawRect: if you perform custom drawing.
  57. // An empty implementation adversely affects performance during animation.
  58. - (void)drawRect:(CGRect)rect {
  59. // Drawing code
  60. }
  61. */
  62. @end