// // ASAddGiftGoodsView.m // Asteria // // Created by xingyu on 2024/5/13. // #import "ASAddGiftGoodsView.h" @interface ASAddGiftGoodsView() @property (nonatomic, strong) UIImageView *goodsImage; @end @implementation ASAddGiftGoodsView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4]; UIView *backView = [[UIView alloc] init]; backView.backgroundColor = Col_FFF; TT_ViewRadius(backView, 8); [self addSubview:backView]; [backView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(self); make.width.mas_equalTo(300); }]; UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [closeBtn setImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal]; [closeBtn addTarget:self action:@selector(_closeClick) forControlEvents:UIControlEventTouchUpInside]; [backView addSubview:closeBtn]; [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(10); make.right.mas_equalTo(-10); make.width.height.mas_equalTo(36); }]; UILabel *topLab = [UILabel labelCreateWithText:@"Congratulations!" font:[UIFont fontWithName:Rob_Bold size:14] textColor:Col_000]; [backView addSubview:topLab]; [topLab mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(backView); make.top.mas_equalTo(56); }]; UILabel *descLab = [UILabel labelCreateWithText:@"You got a free gift" font:[UIFont fontWithName:Rob_Regular size:14] textColor:Col_000]; [backView addSubview:descLab]; [descLab mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(backView); make.top.mas_equalTo(topLab.mas_bottom).offset(10); }]; _goodsImage = [[UIImageView alloc] init]; [backView addSubview:_goodsImage]; [_goodsImage mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(backView); make.top.mas_equalTo(descLab.mas_bottom).offset(10); make.width.height.mas_equalTo(86); }]; UIButton *getBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [getBtn setTitle:@"Get" forState:UIControlStateNormal]; [getBtn setTitleColor:Col_FFF forState:UIControlStateNormal]; getBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:14]; getBtn.backgroundColor = Col_000; [getBtn addTarget:self action:@selector(_addCart) forControlEvents:UIControlEventTouchUpInside]; TT_ViewRadius(getBtn, 4); [backView addSubview:getBtn]; [getBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(34); make.right.mas_equalTo(-34); make.top.equalTo(_goodsImage.mas_bottom).offset(30); make.height.mas_equalTo(35); make.bottom.mas_equalTo(-30); }]; } return self; } - (void)setGiftData:(NSString *)imageStr { NSString *imageAllStr = [NSString stringWithFormat:@"https:%@%@%@",HostPath,ProductImgPath,imageStr]; [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:imageAllStr] placeholderImage:UIImageDefaultImg_SD]; } - (void)_addCart { // [self removeFromSuperview]; if (self.addBlock) { self.addBlock(1); } } - (void)_closeClick { if (self.addBlock) { self.addBlock(0); } } @end