123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // XYMyVoiceRoomListTableViewCell.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/7/7.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYMyVoiceRoomListTableViewCell.h"
- #import "XYMyVoiceRoomListModel.h"
- @interface XYMyVoiceRoomListTableViewCell ()
- @property (nonatomic, strong) UIImageView *headImageView;
- @property (nonatomic, strong) UILabel *categoryNameLabel;
- @property (nonatomic, strong) UILabel *roomRoleLabel;
- @property (nonatomic, strong) UILabel *roomNameLabel;
- @property (nonatomic, strong) UILabel *roomHeatLabel;
- @property (nonatomic, strong) UIView *line;
- @end
- @implementation XYMyVoiceRoomListTableViewCell
- #pragma mark — Public
- + (instancetype)cellWithTableView:(UITableView *)tableView
- {
- static NSString *ID = @"XYMyVoiceRoomListTableViewCell";
- XYMyVoiceRoomListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
- if (cell == nil) {
- cell = [[XYMyVoiceRoomListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)configureModel:(XYMyVoiceRoomListModel *)model
- {
- [self.headImageView sd_setImageWithURL:UrlForString(model.roomCover) placeholderImage:placeholderImage()];
- self.categoryNameLabel.text = model.categoryName;
- CGFloat categoryNameWidht = [self.categoryNameLabel sizeThatFits:CGSizeMake(150.0f, 16.0f)].width + 12.0f;
- [self.categoryNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(categoryNameWidht));
- }];
- self.roomRoleLabel.text = [XYVocieRoomCommonMethod getVoiceRoomRoleTextWithRole:model.roomRole];
- CGFloat roomRoleWidht = [self.roomRoleLabel sizeThatFits:CGSizeMake(150.0f, 16.0f)].width + 12.0f;
- [self.roomRoleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(roomRoleWidht));
- }];
- self.roomNameLabel.text = model.roomName;
- self.roomHeatLabel.text = [NSString stringWithFormat:@"%ld", model.roomHeat];
- }
- #pragma mark — Action
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- [self _setup];
- [self _setupSubViews];
- [self _makeSubViewsConstraint];
- }
- return self;
- }
- #pragma mark - 配置属性
- - (void)_setup {
-
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews {
- [self.contentView addSubview:self.headImageView];
- [self.contentView addSubview:self.categoryNameLabel];
- [self.contentView addSubview:self.roomRoleLabel];
- [self.contentView addSubview:self.roomNameLabel];
- [self.contentView addSubview:self.roomHeatLabel];
- [self.contentView addSubview:self.line];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraint {
- [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(21.0f);
- make.centerY.equalTo(self.contentView);
- make.width.height.equalTo(@38.0f);
- }];
- [self.categoryNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headImageView.mas_right).offset(12.0f);
- make.top.equalTo(self.headImageView).offset(1.0f);
- make.height.equalTo(@16.0f);
- make.width.equalTo(@40.0f);
- }];
- [self.roomRoleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headImageView.mas_right).offset(12.0f);
- make.top.equalTo(self.categoryNameLabel.mas_bottom).offset(5.0f);
- make.height.equalTo(@16.0f);
- make.width.equalTo(@40.0f);
- }];
- [self.roomNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.categoryNameLabel.mas_right).offset(10.0f);
- make.centerY.equalTo(self.categoryNameLabel);
- make.right.lessThanOrEqualTo(self.roomHeatLabel.mas_left).offset(-10.0f);
- }];
- [self.roomHeatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-20.0f);
- make.centerY.equalTo(self.contentView);
- }];
- [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headImageView.mas_right).offset(12.0f);
- make.bottom.right.equalTo(self.contentView);
- make.height.equalTo(@(LINE_HEIGHT));
- }];
- [self.headImageView addViewBorder:Color_Clear redian:38/2];
- [self.categoryNameLabel addViewBorder:Color_Clear redian:8];
- [self.roomRoleLabel addViewBorder:Color_Clear redian:4];
- }
- #pragma mark - Getter/Setter
- - (UIImageView *)headImageView {
- if (!_headImageView) {
- _headImageView = [UIImageView new];
- _headImageView.clipsToBounds = YES;
- _headImageView.contentMode = UIViewContentModeScaleAspectFill;
- }
- return _headImageView;
- }
- - (UILabel *)categoryNameLabel {
- if (!_categoryNameLabel) {
- _categoryNameLabel = [UILabel createLabelTextColor:Color_White fount:Font(10)];
- _categoryNameLabel.textAlignment = NSTextAlignmentCenter;
- _categoryNameLabel.backgroundColor = ColorFromHexString(@"#65CAA6");
- }
- return _categoryNameLabel;
- }
- - (UILabel *)roomRoleLabel {
- if (!_roomRoleLabel) {
- _roomRoleLabel = [UILabel createLabelTextColor:Color_White fount:Font(10)];
- _roomRoleLabel.textAlignment = NSTextAlignmentCenter;
- _roomRoleLabel.backgroundColor = ColorFromHexString(@"#7184F7");
- }
- return _roomRoleLabel;
- }
- - (UILabel *)roomNameLabel {
- if (!_roomNameLabel) {
- _roomNameLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(14)];
- }
- return _roomNameLabel;
- }
- - (UILabel *)roomHeatLabel {
- if (!_roomHeatLabel) {
- _roomHeatLabel = [UILabel createLabelTextColor:Color_TextRed fount:Font(16)];
- _roomHeatLabel.textAlignment = NSTextAlignmentRight;
- }
- return _roomHeatLabel;
- }
- - (UIView *)line {
- if (!_line) {
- _line = [UIView new];
- _line.backgroundColor = Color_line;
- }
- return _line;
- }
- @end
|