// // MORedPacketInfoView.m // MiMoLive // // Created by MiMo on 2025/5/17. // #import "MORedPacketInfoView.h" @interface MORedPacketInfoView () @property (nonatomic, strong) UIView *backgroundView; @property (nonatomic, strong) UILabel *diamondLabel; @property (nonatomic, strong) UIImageView *diamondIcon; @property (nonatomic, strong) UILabel *itemLabel; @property (nonatomic, strong) UIImageView *itemIcon; @property (nonatomic, strong) UIView *separatorView; @end @implementation MORedPacketInfoView - (instancetype)init { self = [super init]; if (self) { [self setupViews]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; [self setupGradientLayerWithView:self.backgroundView startColor:[MOTools colorWithHexString:@"#FFA289"] endColor:[MOTools colorWithHexString:@"#FDC9AD"] layerName:@"gradientLayer" startPoint:(CGPoint) { 0.5, 0 } endPoint:(CGPoint){0.5, 1}]; self.backgroundView.layer.cornerRadius = 15; self.backgroundView.layer.masksToBounds = YES; } - (UILabel *)createLabelWithFontSize:(CGFloat)fontSize { UILabel *label = [[UILabel alloc] init]; label.textColor = [MOTools colorWithHexString:@"#A13A00"]; label.font = [MOTextTools getTheFontWithSize:fontSize AndFontName:kNormalContentBlodFontStr]; return label; } - (UIImageView *)createIconWithName:(NSString *)name { UIImage *image = [UIImage imageNamed:name]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.contentMode = UIViewContentModeScaleAspectFit; return imageView; } - (void)setupViews { // 背景视图 self.backgroundView = [[UIView alloc] init]; self.backgroundView.backgroundColor = [UIColor colorWithRed:1.0 green:0.8 blue:0.8 alpha:1.0]; self.backgroundView.layer.cornerRadius = 15; [self addSubview:self.backgroundView]; // 子控件 self.diamondLabel = [self createLabelWithFontSize:16.0]; self.diamondIcon = [self createIconWithName:@"icon_red_list_diamond"]; self.separatorView = [[UIView alloc] init]; self.separatorView.backgroundColor = [MOTools colorWithHexString:@"#B93900"]; self.itemLabel = [self createLabelWithFontSize:14.0]; self.itemIcon = [self createIconWithName:@"icon_red_packet_small"]; // 加入背景视图中 [self.backgroundView addSubview:self.diamondLabel]; [self.backgroundView addSubview:self.diamondIcon]; [self.backgroundView addSubview:self.separatorView]; [self.backgroundView addSubview:self.itemLabel]; [self.backgroundView addSubview:self.itemIcon]; // 使用 Masonry 布局 [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.mas_equalTo(0); make.height.mas_equalTo(30); }]; [self.diamondLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backgroundView.mas_left).offset(10); make.centerY.equalTo(self.backgroundView); }]; [self.diamondIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.diamondLabel.mas_right).offset(6); make.centerY.equalTo(self.backgroundView); make.width.mas_equalTo(14); make.height.mas_equalTo(11); }]; [self.separatorView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.diamondIcon.mas_right).offset(6); make.centerY.equalTo(self.backgroundView); make.size.mas_equalTo(CGSizeMake(1, 9)); }]; [self.itemLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.separatorView.mas_right).offset(6); make.centerY.equalTo(self.backgroundView); }]; [self.itemIcon mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.itemLabel.mas_right).offset(3); make.right.equalTo(self.backgroundView.mas_right).offset(-10); make.centerY.equalTo(self.backgroundView); make.size.mas_equalTo(CGSizeMake(13, 14)); }]; } - (void)setDiamondCount:(NSInteger)diamondCount itemCount:(NSInteger)itemCount { self.diamondLabel.text = [NSString stringWithFormat:@"%ld", (long)diamondCount]; self.itemLabel.text = [NSString stringWithFormat:@"%ld", (long)itemCount]; } @end