KSTipsAlert.m 1.9 KB

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