// // XPRoomGiftBroadcastView.m // xplan-ios // // Created by 冯硕 on 2021/11/18. // #import "XPRoomGiftBroadcastView.h" ///Third #import ///Tool #import "ThemeColor+Room.h" ///Model #import "GiftReceiveInfoModel.h" ///View #import "NetImageView.h" @interface XPRoomGiftBroadcastView () ///背景 @property (nonatomic,strong) UIImageView *backImageView; ///赠送者头像 @property(nonatomic,strong) NetImageView *senderAvatarView; ///赠送内容 @property(nonatomic,strong) MarqueeLabel *pi_contentView; ///礼物 @property (nonatomic,strong) NetImageView *giftImageView; ///数量 @property (nonatomic,strong) UILabel *countLabel; ///房间名 @property (nonatomic,strong) UILabel *roomNameLabel; ///房间背景 @property (nonatomic,strong) UIImageView *pi_roomIconView; ///去围观 @property(nonatomic,strong) UIButton *circuseeBtn; @end @implementation XPRoomGiftBroadcastView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; [self initEvents]; } return self; } #pragma mark - Response - (void)didClickEnterRoom { if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomGiftBroadcastView:enterRoom:roomName:)]) { [self.delegate xPRoomGiftBroadcastView:self enterRoom:[NSString stringWithFormat:@"%ld", self.broadcastModel.roomUid] roomName:self.broadcastModel.roomTitle]; } } #pragma mark - Private Method - (void)initSubViews { [self addSubview:self.backImageView]; [self.backImageView addSubview:self.senderAvatarView]; [self.backImageView addSubview:self.pi_contentView]; [self.backImageView addSubview:self.pi_roomIconView]; [self.backImageView addSubview:self.roomNameLabel]; [self.backImageView addSubview:self.circuseeBtn]; [self.backImageView addSubview:self.giftImageView]; [self.backImageView addSubview:self.countLabel]; } - (void)initSubViewConstraints { [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self); }]; [self.senderAvatarView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(kGetScaleWidth(44)); make.leading.mas_equalTo(kGetScaleWidth(23)); make.centerY.equalTo(self.backImageView); }]; [self.pi_contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.senderAvatarView.mas_trailing).mas_offset(kGetScaleWidth(13)); make.top.mas_equalTo(kGetScaleWidth(18)); make.trailing.mas_equalTo(-kGetScaleWidth(133)); make.height.mas_equalTo(kGetScaleWidth(14)); }]; [self.pi_roomIconView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(kGetScaleWidth(12)); make.leading.equalTo(self.senderAvatarView.mas_trailing).mas_offset(kGetScaleWidth(11)); make.top.mas_equalTo(kGetScaleWidth(39)); }]; [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(kGetScaleWidth(92)); make.top.mas_equalTo(kGetScaleWidth(40)); make.height.mas_equalTo(kGetScaleWidth(12)); make.width.mas_equalTo(kGetScaleWidth(105)); }]; [self.circuseeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(kGetScaleWidth(44)); make.height.mas_equalTo(kGetScaleWidth(20)); make.leading.equalTo(self.roomNameLabel.mas_trailing).mas_offset(kGetScaleWidth(5)); make.centerY.equalTo(self.roomNameLabel); }]; [self.giftImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(64), kGetScaleWidth(64))); make.centerY.mas_equalTo(self.backImageView); make.trailing.mas_equalTo(-kGetScaleWidth(64)); }]; [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self.giftImageView.mas_trailing).offset(kGetScaleWidth(2)); make.centerY.mas_equalTo(self.backImageView); }]; } - (void)initEvents { [self.circuseeBtn addTarget:self action:@selector(didClickEnterRoom) forControlEvents:UIControlEventTouchUpInside]; } - (void)updateSubviews:(BroadCastLevel)level { UIColor * lineColor; UIColor *bgBtnColor; NSString * bgImageName; switch (level) { case BroadCastLevel_Normal: { lineColor = UIColorFromRGB(0x66B5FF); bgBtnColor = UIColorFromRGB(0x283889); bgImageName = @"pi_room_gift_broadcast_low_bg"; } break; case BroadCastLevel_Middle: { lineColor = UIColorFromRGB(0xFE9FFF); bgBtnColor = UIColorFromRGB(0x49157D); bgImageName = @"pi_room_gift_broadcast_middle_bg"; } break; case BroadCastLevel_High: { lineColor = UIColorFromRGB(0xFFED77); bgBtnColor = UIColorFromRGB(0x87152D); bgImageName = @"pi_room_gift_broadcast_high_bg"; } break; default: { lineColor = UIColorFromRGB(0x66B5FF); bgBtnColor = UIColorFromRGB(0x283889); bgImageName = @"pi_room_gift_broadcast_low_bg"; } break; } self.backImageView.image = [UIImage imageNamed:bgImageName]; self.circuseeBtn.layer.borderColor = lineColor.CGColor; self.circuseeBtn.backgroundColor = bgBtnColor; } #pragma mark - Getters And Setters - (void)setBroadcastModel:(GiftReceiveInfoModel *)broadcastModel { _broadcastModel = broadcastModel; if (_broadcastModel) { NSString *sendUserNick = _broadcastModel.sendUserNick ?: @""; NSString *recvUserNick = _broadcastModel.recvUserNick ?: @""; self.senderAvatarView.imageUrl = _broadcastModel.sendUserAvatar; sendUserNick = sendUserNick.length > 6 ? [sendUserNick substringToIndex:6] : sendUserNick; recvUserNick = recvUserNick.length > 6 ? [recvUserNick substringToIndex:6] : recvUserNick; NSString *giftName = [NSString stringWithFormat:@"%@ %@ %@ %@",_broadcastModel.sendUserNick,YMLocalizedString(@"XPRoomYearActivityView0"),_broadcastModel.recvUserNick,_broadcastModel.giftName]; NSMutableAttributedString *giftNameAtt = [[NSMutableAttributedString alloc]initWithString:giftName attributes:@{NSFontAttributeName:kFontMedium(14),NSForegroundColorAttributeName:[UIColor whiteColor]}]; [giftNameAtt addAttributes:@{NSFontAttributeName:kFontMedium(14),NSForegroundColorAttributeName:UIColorFromRGB(0xFFE468)} range:[giftName rangeOfString:sendUserNick]]; [giftNameAtt addAttributes:@{NSFontAttributeName:kFontMedium(14),NSForegroundColorAttributeName:UIColorFromRGB(0xFFE468)} range:[giftName rangeOfString:recvUserNick]]; self.pi_contentView.attributedText = giftNameAtt; self.giftImageView.imageUrl = _broadcastModel.giftUrl; self.roomNameLabel.text = _broadcastModel.roomTitle; if(_broadcastModel.giftNum > 1){ self.countLabel.text = [NSString stringWithFormat:@"x%ld", _broadcastModel.giftNum]; } [self updateSubviews:_broadcastModel.levelNum]; } } - (UIImageView *)backImageView { if (!_backImageView) { _backImageView = [[UIImageView alloc] init]; _backImageView.userInteractionEnabled = YES; } return _backImageView; } -(NetImageView *)senderAvatarView{ if(!_senderAvatarView){ NetImageConfig *config = [[NetImageConfig alloc]init]; config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; _senderAvatarView = [[NetImageView alloc]initWithConfig:config]; _senderAvatarView.layer.cornerRadius = kGetScaleWidth(44)/2; _senderAvatarView.layer.masksToBounds = YES; _senderAvatarView.userInteractionEnabled = YES; } return _senderAvatarView; } - (MarqueeLabel *)pi_contentView{ if(!_pi_contentView){ _pi_contentView = [[MarqueeLabel alloc] init]; _pi_contentView.scrollDuration = 6.0; _pi_contentView.fadeLength = 8.0f; _pi_contentView.textAlignment = NSTextAlignmentCenter; } return _pi_contentView; } - (NetImageView *)giftImageView { if (!_giftImageView) { _giftImageView = [[NetImageView alloc] init]; } return _giftImageView; } - (UILabel *)countLabel { if (!_countLabel) { _countLabel = [[UILabel alloc] init]; _countLabel.textColor = UIColorFromRGB(0xFFE468); _countLabel.font = kFontHeavy(16); } return _countLabel; } - (UILabel *)roomNameLabel { if (!_roomNameLabel) { _roomNameLabel = [[UILabel alloc] init]; _roomNameLabel.font = kFontRegular(12); _roomNameLabel.textColor = [UIColor whiteColor]; } return _roomNameLabel; } - (UIImageView *)pi_roomIconView{ if(!_pi_roomIconView){ _pi_roomIconView = [UIImageView new]; _pi_roomIconView.image = kImage(@"pi_room_gift_broadcast_room_icon"); } return _pi_roomIconView; } - (UIButton *)circuseeBtn{ if(!_circuseeBtn){ _circuseeBtn = [UIButton new]; [_circuseeBtn setTitle:YMLocalizedString(@"XPAcrpssRoomPKPanelView3") forState:UIControlStateNormal]; _circuseeBtn.titleLabel.font = kFontRegular(10); _circuseeBtn.layer.cornerRadius = kGetScaleWidth(20)/2; _circuseeBtn.layer.borderWidth = 1; _circuseeBtn.layer.masksToBounds = YES; } return _circuseeBtn; } @end