// // YMStopServicePopupView.m // MSYOUPAI // // Created by macmini on 2025/6/7. // Copyright © 2025 MS. All rights reserved. // #import "YMStopServicePopupView.h" @interface YMStopServicePopupView () @property (nonatomic, strong) UIView *backgroundMaskView; @property (nonatomic, strong) UIView *bgv; @property (nonatomic, strong) UIImageView *bgImgv; @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UITextView *contentTV; @property (nonatomic, strong) YMAdvertModel *model; @end @implementation YMStopServicePopupView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setupUI]; } return self; } - (void)setupUI { self.backgroundColor = [UIColor clearColor]; // Background Mask self.backgroundMaskView = [[UIView alloc] initWithFrame:self.bounds]; self.backgroundMaskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; self.backgroundMaskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [self addSubview:self.backgroundMaskView]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; [self.backgroundMaskView addGestureRecognizer:tapGesture]; // Content View self.bgv = [[UIView alloc] init]; self.bgv.backgroundColor = [UIColor whiteColor]; self.bgv.layer.cornerRadius = adapt(16); self.bgv.clipsToBounds = YES; [self.bgv addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { }]]; [self addSubview:self.bgv]; self.bgImgv = [[UIImageView alloc] init]; self.bgImgv.contentMode = UIViewContentModeScaleAspectFill; [self.bgv addSubview:self.bgImgv]; // Title Label self.titleLabel = [[UILabel alloc] init]; self.titleLabel.font = [UIFont boldSystemFontOfSize:30.0]; self.titleLabel.textAlignment = NSTextAlignmentCenter; self.titleLabel.textColor = UIColor.blackColor; [self.bgv addSubview:self.titleLabel]; self.contentTV = [[UITextView alloc] init]; self.contentTV.font = [UIFont systemFontOfSize:15.0]; self.contentTV.textAlignment = NSTextAlignmentLeft; self.contentTV.textColor = UIColor.grayColor; self.contentTV.editable = NO; self.contentTV.backgroundColor = UIColor.clearColor; [self.bgv addSubview:self.contentTV]; [self setupLayoutConstraints]; } - (void)setupLayoutConstraints { self.bgv.translatesAutoresizingMaskIntoConstraints = NO; self.bgImgv.translatesAutoresizingMaskIntoConstraints = NO; self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; self.contentTV.translatesAutoresizingMaskIntoConstraints = NO; CGFloat contentWidth = CGRectGetWidth(UIScreen.mainScreen.bounds) - adapt(80); CGFloat contentHeight = adapt(380); // Adjusted height [NSLayoutConstraint activateConstraints:@[ [self.bgv.centerXAnchor constraintEqualToAnchor:self.centerXAnchor], [self.bgv.centerYAnchor constraintEqualToAnchor:self.centerYAnchor], [self.bgv.widthAnchor constraintEqualToConstant:contentWidth], [self.bgv.heightAnchor constraintEqualToConstant:contentHeight], [self.bgImgv.topAnchor constraintEqualToAnchor:self.bgv.topAnchor], [self.bgImgv.leadingAnchor constraintEqualToAnchor:self.bgv.leadingAnchor], [self.bgImgv.trailingAnchor constraintEqualToAnchor:self.bgv.trailingAnchor], [self.bgImgv.bottomAnchor constraintEqualToAnchor:self.bgv.bottomAnchor], [self.titleLabel.topAnchor constraintEqualToAnchor:self.bgv.topAnchor constant:40], [self.titleLabel.leadingAnchor constraintEqualToAnchor:self.bgv.leadingAnchor constant:20], [self.titleLabel.trailingAnchor constraintEqualToAnchor:self.bgv.trailingAnchor constant:-20], [self.contentTV.topAnchor constraintEqualToAnchor:self.titleLabel.bottomAnchor constant:30], [self.contentTV.leadingAnchor constraintEqualToAnchor:self.bgv.leadingAnchor constant:20], [self.contentTV.trailingAnchor constraintEqualToAnchor:self.bgv.trailingAnchor constant:-20], [self.contentTV.bottomAnchor constraintEqualToAnchor:self.bgv.bottomAnchor constant:-20], ]]; [self.titleLabel setContentHuggingPriority:999 forAxis:UILayoutConstraintAxisVertical]; [self.titleLabel setContentCompressionResistancePriority:999 forAxis:UILayoutConstraintAxisVertical]; } #pragma mark - Actions #pragma mark - Public Methods - (void)showInView:(UIView *)view { self.frame = view.bounds; [view addSubview:self]; self.alpha = 0; self.bgv.transform = CGAffineTransformMakeScale(0.5, 0.5); [UIView animateWithDuration:0.3 animations:^{ self.alpha = 1; self.bgv.transform = CGAffineTransformIdentity; }]; } - (void)dismiss { [UIView animateWithDuration:0.3 animations:^{ self.alpha = 0; self.bgv.transform = CGAffineTransformMakeScale(0.5, 0.5); } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } - (void)setModel:(YMAdvertModel *)model { _model = model; [_bgImgv sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.image]]; _titleLabel.text = model.title; _contentTV.text = model.content; } @end