// // YMNewUserRoomGiftView.m // YUMI // // Created by YUMI on 2022/7/26. // #import "XPNewUserRoomGiftView.h" ///Third #import #import "NetImageView.h" ///Tool #import "DJDKMIMOMColor.h" #import "UIImage+Utils.h" #import "TTPopup.h" #import "YUMIMacroUitls.h" @interface XPNewUserRoomGiftView () @property (nonatomic, strong) UIImageView *bgImageView; ///显示标题 @property (nonatomic,strong) UILabel *titleLabel; @property (nonatomic, strong) NetImageView *iconImageView; @property (nonatomic, strong) UILabel *descLabel; ///关闭按钮 @property (nonatomic,strong) UIButton *closeButton; @end @implementation XPNewUserRoomGiftView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { self.layer.masksToBounds = YES; self.layer.cornerRadius = 15; self.backgroundColor = [UIColor clearColor]; [self addSubview:self.bgImageView]; [self addSubview:self.titleLabel]; [self addSubview:self.iconImageView]; [self addSubview:self.descLabel]; [self addSubview:self.closeButton]; } - (void)initSubViewConstraints { [self mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(260); make.height.mas_equalTo(376); }]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.leading.trailing.mas_equalTo(0); make.height.mas_equalTo(320); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(130); make.leading.trailing.mas_equalTo(self).inset(15); make.height.mas_equalTo(17); }]; [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self); make.width.height.mas_equalTo(100); make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(13); }]; [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.iconImageView.mas_bottom).mas_offset(19); make.height.mas_equalTo(17); make.leading.trailing.mas_equalTo(self).inset(15); }]; [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(32, 32)); make.top.mas_equalTo(self.bgImageView.mas_bottom).offset(24); make.centerX.mas_equalTo(self); }]; } #pragma mark - Event Response - (void)closeButtonAction:(UIButton *)sender { [TTPopup dismiss]; } #pragma mark - Getters And Setters - (void)setGiftInfo:(GiftInfoModel *)giftInfo { NSString *giftStr = [NSString stringWithFormat:@"%@*%zd", giftInfo.giftName, giftInfo.count]; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPNewUserRoomGiftView0") attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:UIColorFromRGB(0xEEFEEC)}]; [str appendAttributedString:[[NSMutableAttributedString alloc] initWithString:giftStr attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12 weight:UIFontWeightHeavy],NSForegroundColorAttributeName:UIColorFromRGB(0xEEFEEC)}]]; self.titleLabel.attributedText = str; self.iconImageView.imageUrl = giftInfo.giftUrl; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.textAlignment = NSTextAlignmentCenter; _titleLabel.font = [UIFont systemFontOfSize:12]; _titleLabel.textColor = UIColorFromRGB(0xEEFEEC); } return _titleLabel; } - (UILabel *)descLabel { if (!_descLabel) { _descLabel = [[UILabel alloc] init]; _descLabel.textAlignment = NSTextAlignmentCenter; _descLabel.font = [UIFont systemFontOfSize:12]; _descLabel.textColor = UIColorFromRGB(0xEEFEEC); _descLabel.text = YMLocalizedString(@"XPNewUserRoomGiftView1"); } return _descLabel; } - (NetImageView *)iconImageView { if (!_iconImageView) { _iconImageView = [[NetImageView alloc] init]; _iconImageView.layer.cornerRadius = 12; _iconImageView.layer.masksToBounds = YES; } return _iconImageView; } - (UIImageView *)bgImageView { if (!_bgImageView) { _bgImageView = [[UIImageView alloc] init]; _bgImageView.image = [UIImage imageNamed:@"room_newUser_gift_bg"]; } return _bgImageView; } - (UIButton *)closeButton { if (!_closeButton) { _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeButton setImage:[UIImage imageNamed:@"anchorPk_result_close"] forState:UIControlStateNormal]; [_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside]; } return _closeButton; } @end