KSNewConfirmAlertView.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KSNewConfirmAlertView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2023/9/26.
  6. //
  7. #import "KSNewConfirmAlertView.h"
  8. #import <KSToolLibrary/UIView+Animation.h>
  9. @interface KSNewConfirmAlertView ()
  10. @property (nonatomic, copy) KSConfirmAlertCallback callback;
  11. @property (weak, nonatomic) IBOutlet UILabel *headTitle;
  12. @property (weak, nonatomic) IBOutlet UILabel *descLabel;
  13. @property (weak, nonatomic) IBOutlet UIButton *sureButton;
  14. @end
  15. @implementation KSNewConfirmAlertView
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. [self.sureButton setBackgroundColor:THEMECOLOR];
  19. }
  20. + (instancetype)shareInstance {
  21. KSNewConfirmAlertView *view = [[[NSBundle mainBundle] loadNibNamed:@"KSNewConfirmAlertView" owner:nil options:nil] firstObject];
  22. return view;
  23. }
  24. - (void)configTitle:(NSString *)title desc:(NSString *)desc callback:(KSConfirmAlertCallback)callback {
  25. if (callback) {
  26. self.callback = callback;
  27. }
  28. [self.headTitle setText:title];
  29. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  30. [paragraphStyle setLineSpacing:4];//调整行间距
  31. [paragraphStyle setAlignment:NSTextAlignmentCenter];
  32. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString returnNoNullStringWithString:desc] attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:16.0f],NSForegroundColorAttributeName:HexRGB(0x666666)}];
  33. self.descLabel.attributedText = attrStr;
  34. }
  35. - (void)showAlert {
  36. UIWindow *window = [NSObject getKeyWindow];
  37. [window addSubview:self];
  38. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.right.top.bottom.mas_equalTo(window);
  40. }];
  41. [self setPopAnimation];
  42. }
  43. - (void)hiddenAction {
  44. [self removeFromSuperview];
  45. }
  46. - (IBAction)sureAction:(id)sender {
  47. if (self.callback) {
  48. self.callback(YES);
  49. }
  50. [self hiddenAction];
  51. }
  52. - (IBAction)cancleAction:(id)sender {
  53. if (self.callback) {
  54. self.callback(NO);
  55. }
  56. [self hiddenAction];
  57. }
  58. /*
  59. // Only override drawRect: if you perform custom drawing.
  60. // An empty implementation adversely affects performance during animation.
  61. - (void)drawRect:(CGRect)rect {
  62. // Drawing code
  63. }
  64. */
  65. @end