ASDefualtAlertV.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // ASDefualtAlertV.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/17.
  6. //
  7. #import "ASDefualtAlertV.h"
  8. #import "ASHomeAlertWindow.h"
  9. @interface ASDefualtAlertV ()
  10. @property (nonatomic, strong) UIView *bgV;
  11. @property (nonatomic, strong) UIButton *closeBt;
  12. @property (nonatomic, strong) UILabel *msgLb;
  13. @end
  14. @implementation ASDefualtAlertV
  15. - (void)setMsg:(NSString *)msg {
  16. self.msgLb.text = msg;
  17. }
  18. - (void)setViewStyle:(ASAlertWidthStyle)style {
  19. [self mas_updateConstraints:^(MASConstraintMaker *make) {
  20. switch (style) {
  21. case ASAlertWidthStyleLittle:
  22. make.width.equalTo(@180);
  23. break;
  24. case ASAlertWidthStyleMiddle:
  25. make.width.equalTo(@230);
  26. default:
  27. make.width.equalTo(@(KScreenWidth-60));
  28. break;
  29. }
  30. }];
  31. }
  32. - (instancetype)initWithFrame:(CGRect)frame {
  33. self = [super initWithFrame:frame];
  34. if (self) {
  35. [self loadSubV];
  36. }
  37. return self;
  38. }
  39. - (void)loadSubV {
  40. [self addSubview:self.bgV];
  41. [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.center.equalTo(self);
  43. make.top.leading.greaterThanOrEqualTo(self).offset(10);
  44. make.width.equalTo(@180);
  45. }];
  46. [self.bgV addSubview:self.msgLb];
  47. [self.bgV addSubview:self.closeBt];
  48. [self.msgLb mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.bottom.equalTo(self.bgV).offset(-30);
  50. make.trailing.equalTo(self.bgV).offset(-20);
  51. make.top.equalTo(self.closeBt.mas_bottom).offset(10);
  52. make.leading.equalTo(self.bgV).offset(20);
  53. }];
  54. [self.closeBt mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.top.equalTo(self.bgV).offset(10);
  56. make.trailing.equalTo(self.bgV).offset(-10);
  57. make.width.height.equalTo(@36);
  58. }];
  59. }
  60. - (UILabel *)msgLb {
  61. if (!_msgLb) {
  62. UILabel *lb = [UILabel baseLb];
  63. lb.textAlignment = NSTextAlignmentCenter;
  64. lb.font = [UIFont fontWithName:Rob_Regular size:14];
  65. lb.numberOfLines = 0;
  66. lb.qmui_lineHeight = 24;
  67. lb.textColor = Col_000;
  68. _msgLb = lb;
  69. }
  70. return _msgLb;
  71. }
  72. - (UIButton *)closeBt {
  73. if (!_closeBt) {
  74. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  75. [btn setImage:[UIImage imageNamed:@"productLsit_filter_close"] forState:UIControlStateNormal];
  76. [btn addTarget:self action:@selector(closeBTAction) forControlEvents:UIControlEventTouchUpInside];
  77. _closeBt = btn;
  78. }
  79. return _closeBt;
  80. }
  81. - (UIView *)bgV {
  82. if (!_bgV) {
  83. UIView *v = [UIView baseV];
  84. v.backgroundColor = Col_FFF;
  85. v.layer.cornerRadius = 8;
  86. v.layer.masksToBounds = true;
  87. _bgV = v;
  88. }
  89. return _bgV;
  90. }
  91. - (void)closeBTAction {
  92. [ASHomeAlertWindow clearWindow];
  93. if (self.closeAction) {
  94. self.closeAction();
  95. }
  96. }
  97. @end