// // MicroView.m // DingDangApp // // Created by apple on 2023/5/27. // #import "RoomMicroView.h" #import "NSString+Custom.h" @implementation RoomMicroView - (void)initView{ [self headeImageView]; [self incomeBtn]; [self nameLabel]; } - (void)starAnimateEmojiImage:(NSString *)emojiUrl{ [self.headeImageView starAnimateEmojiImage:emojiUrl]; } - (void)setMicroModel:(RoomMicroModel *)microModel{ _microModel = microModel; if(microModel.user_id == nil){ self.headeImageView.microModel = microModel; [self.incomeBtn setTitle:@"0" forState:UIControlStateNormal]; self.nameLabel.text = @""; return; } self.headeImageView.microModel = microModel; self.incomeBtn.backgroundColor = [UIColor clearColor]; self.incomeBtn.layer.borderColor = UIColor.whiteColor.CGColor; [self.incomeBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal]; self.incomeBtn.hidden = YES; //麦上有人 if([ToolsObject isBlankString:microModel.user_id].length>0){ self.nameLabel.text = microModel.nickname; [self.incomeBtn setTitleColor:Kwhite_color forState:UIControlStateNormal]; [self.incomeBtn setImage:[UIImage imageNamed:@"room_1"] forState:UIControlStateNormal]; [self.incomeBtn setImagePositionWithType:SSImagePositionTypeLeft spacing:1]; [self.incomeBtn setTitle:microModel.mic_seat_valueString forState:UIControlStateNormal]; self.incomeBtn.hidden = NO; }else{ [self.incomeBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal]; [self.incomeBtn setTitle:@"上麦" forState:UIControlStateNormal]; self.nameLabel.text = microModel.mic_idString; self.incomeBtn.hidden = YES; } if([microModel.is_lock boolValue]==YES){ self.incomeBtn.hidden = NO; self.nameLabel.text = @""; [self.incomeBtn setTitle:@"已锁麦" forState:UIControlStateNormal]; self.incomeBtn.backgroundColor = [[UIColor jk_colorWithHex:0x000000] colorWithAlphaComponent:0.3]; self.incomeBtn.layer.borderColor = UIColor.clearColor.CGColor; [self.incomeBtn setTitleColor:[UIColor.whiteColor colorWithAlphaComponent:0.4] forState:UIControlStateNormal]; } if(self.incomeBtn.hidden){ [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).mas_offset(KAdaptedWidth(10)); make.right.mas_equalTo(self.mas_right).mas_offset(KAdaptedWidth(-10)); make.top.mas_equalTo(self.incomeBtn.mas_top).mas_offset(0); }]; }else{ [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).mas_offset(KAdaptedWidth(10)); make.right.mas_equalTo(self.mas_right).mas_offset(KAdaptedWidth(-10)); make.top.mas_equalTo(self.incomeBtn.mas_bottom).mas_offset(2); }]; } CGFloat with = [self.incomeBtn.titleLabel.text getSizeWithStrFloat:10].width+20; if(with 0){ if(self.backIncomeTapBlock){ self.backIncomeTapBlock(self.microModel); } }else{ if(self.backHeaderTapBlock){ self.backHeaderTapBlock(self.microModel); } } } - (RoomMicroHeaderView *)headeImageView{ if (!_headeImageView) { _headeImageView = [[RoomMicroHeaderView alloc] init]; _headeImageView.backgroundColor = [UIColor clearColor]; [self addSubview:_headeImageView]; WeakSelf(ws); _headeImageView.headerImageBtnBlock = ^{ if(ws.backHeaderTapBlock){ ws.backHeaderTapBlock(ws.microModel); } }; [_headeImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(0, 0, 0, 0)); }]; } return _headeImageView; } - (UILabel *)nameLabel{ if (!_nameLabel) { _nameLabel = [[UILabel alloc] init]; _nameLabel.textColor = Kwhite_color; _nameLabel.font = KFontMedium(10); _nameLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:_nameLabel]; [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.mas_left).mas_offset(KAdaptedWidth(10)); make.right.mas_equalTo(self.mas_right).mas_offset(KAdaptedWidth(-10)); make.top.mas_equalTo(self.incomeBtn.mas_bottom).mas_offset(2); }]; } return _nameLabel; } - (UIButton *)incomeBtn{ if (!_incomeBtn) { _incomeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_incomeBtn setTitle:@"0" forState:UIControlStateNormal]; [_incomeBtn setTitleColor:Kwhite_color forState:UIControlStateNormal]; _incomeBtn.titleLabel.font = KFontRegular(10); [_incomeBtn setImage:[UIImage imageNamed:@"room_1"] forState:UIControlStateNormal]; [_incomeBtn setImagePositionWithType:SSImagePositionTypeLeft spacing:1]; [_incomeBtn addTarget:self action:@selector(incomeBtnClick) forControlEvents:UIControlEventTouchUpInside]; // Initialization code _incomeBtn.layer.cornerRadius = KAdaptedHeight(8); _incomeBtn.layer.masksToBounds = YES; _incomeBtn.layer.borderWidth = 1; _incomeBtn.layer.borderColor = UIColor.whiteColor.CGColor; [self addSubview:_incomeBtn]; [_incomeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(KAdaptedWidth(53)); make.top.mas_equalTo(self.headeImageView.headerImageView.mas_bottom).mas_offset(5); make.height.mas_equalTo(KAdaptedHeight(16)); make.centerX.mas_equalTo(self).mas_offset(0); }]; } return _incomeBtn; } @end