YMStopServicePopupView.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // YMStopServicePopupView.m
  3. // MSYOUPAI
  4. //
  5. // Created by macmini on 2025/6/7.
  6. // Copyright © 2025 MS. All rights reserved.
  7. //
  8. #import "YMStopServicePopupView.h"
  9. @interface YMStopServicePopupView ()<UITextFieldDelegate>
  10. @property (nonatomic, strong) UIView *backgroundMaskView;
  11. @property (nonatomic, strong) UIView *bgv;
  12. @property (nonatomic, strong) UIImageView *bgImgv;
  13. @property (nonatomic, strong) UILabel *titleLabel;
  14. @property (nonatomic, strong) UITextView *contentTV;
  15. @property (nonatomic, strong) YMAdvertModel *model;
  16. @end
  17. @implementation YMStopServicePopupView
  18. - (instancetype)initWithFrame:(CGRect)frame {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self setupUI];
  22. }
  23. return self;
  24. }
  25. - (void)setupUI {
  26. self.backgroundColor = [UIColor clearColor];
  27. // Background Mask
  28. self.backgroundMaskView = [[UIView alloc] initWithFrame:self.bounds];
  29. self.backgroundMaskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
  30. self.backgroundMaskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  31. [self addSubview:self.backgroundMaskView];
  32. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
  33. [self.backgroundMaskView addGestureRecognizer:tapGesture];
  34. // Content View
  35. self.bgv = [[UIView alloc] init];
  36. self.bgv.backgroundColor = [UIColor whiteColor];
  37. self.bgv.layer.cornerRadius = adapt(16);
  38. self.bgv.clipsToBounds = YES;
  39. [self.bgv addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { }]];
  40. [self addSubview:self.bgv];
  41. self.bgImgv = [[UIImageView alloc] init];
  42. self.bgImgv.contentMode = UIViewContentModeScaleAspectFill;
  43. [self.bgv addSubview:self.bgImgv];
  44. // Title Label
  45. self.titleLabel = [[UILabel alloc] init];
  46. self.titleLabel.font = [UIFont boldSystemFontOfSize:30.0];
  47. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  48. self.titleLabel.textColor = UIColor.blackColor;
  49. [self.bgv addSubview:self.titleLabel];
  50. self.contentTV = [[UITextView alloc] init];
  51. self.contentTV.font = [UIFont systemFontOfSize:15.0];
  52. self.contentTV.textAlignment = NSTextAlignmentLeft;
  53. self.contentTV.textColor = UIColor.grayColor;
  54. self.contentTV.editable = NO;
  55. self.contentTV.backgroundColor = UIColor.clearColor;
  56. [self.bgv addSubview:self.contentTV];
  57. [self setupLayoutConstraints];
  58. }
  59. - (void)setupLayoutConstraints {
  60. self.bgv.translatesAutoresizingMaskIntoConstraints = NO;
  61. self.bgImgv.translatesAutoresizingMaskIntoConstraints = NO;
  62. self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
  63. self.contentTV.translatesAutoresizingMaskIntoConstraints = NO;
  64. CGFloat contentWidth = CGRectGetWidth(UIScreen.mainScreen.bounds) - adapt(80);
  65. CGFloat contentHeight = adapt(380); // Adjusted height
  66. [NSLayoutConstraint activateConstraints:@[
  67. [self.bgv.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
  68. [self.bgv.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
  69. [self.bgv.widthAnchor constraintEqualToConstant:contentWidth],
  70. [self.bgv.heightAnchor constraintEqualToConstant:contentHeight],
  71. [self.bgImgv.topAnchor constraintEqualToAnchor:self.bgv.topAnchor],
  72. [self.bgImgv.leadingAnchor constraintEqualToAnchor:self.bgv.leadingAnchor],
  73. [self.bgImgv.trailingAnchor constraintEqualToAnchor:self.bgv.trailingAnchor],
  74. [self.bgImgv.bottomAnchor constraintEqualToAnchor:self.bgv.bottomAnchor],
  75. [self.titleLabel.topAnchor constraintEqualToAnchor:self.bgv.topAnchor constant:40],
  76. [self.titleLabel.leadingAnchor constraintEqualToAnchor:self.bgv.leadingAnchor constant:20],
  77. [self.titleLabel.trailingAnchor constraintEqualToAnchor:self.bgv.trailingAnchor constant:-20],
  78. [self.contentTV.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:30],
  79. [self.contentTV.leadingAnchor constraintEqualToAnchor:self.bgv.leadingAnchor constant:20],
  80. [self.contentTV.trailingAnchor constraintEqualToAnchor:self.bgv.trailingAnchor constant:-20],
  81. [self.contentTV.bottomAnchor constraintEqualToAnchor:self.bgv.bottomAnchor constant:-20],
  82. ]];
  83. [self.titleLabel setContentHuggingPriority:999 forAxis:UILayoutConstraintAxisVertical];
  84. [self.titleLabel setContentCompressionResistancePriority:999 forAxis:UILayoutConstraintAxisVertical];
  85. }
  86. #pragma mark - Actions
  87. #pragma mark - Public Methods
  88. - (void)showInView:(UIView *)view {
  89. self.frame = view.bounds;
  90. [view addSubview:self];
  91. self.alpha = 0;
  92. self.bgv.transform = CGAffineTransformMakeScale(0.5, 0.5);
  93. [UIView animateWithDuration:0.3 animations:^{
  94. self.alpha = 1;
  95. self.bgv.transform = CGAffineTransformIdentity;
  96. }];
  97. }
  98. - (void)dismiss {
  99. [UIView animateWithDuration:0.3 animations:^{
  100. self.alpha = 0;
  101. self.bgv.transform = CGAffineTransformMakeScale(0.5, 0.5);
  102. } completion:^(BOOL finished) {
  103. [self removeFromSuperview];
  104. }];
  105. }
  106. - (void)setModel:(YMAdvertModel *)model {
  107. _model = model;
  108. [_bgImgv sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.image]];
  109. _titleLabel.text = model.title;
  110. _contentTV.text = model.content;
  111. }
  112. @end