// // UserCell.m // Youth // // Created by mambaxie on 2022/1/2. // #import "UserCell.h" @interface UserCell () @property (nonatomic, strong) PYThemeButton *chatButton; @property (nonatomic, strong) AvatarView *avatarView; @property (nonatomic, strong) UILabel *nickNameLabel; @property (nonatomic, strong) UILabel *sloganLabel; @property (nonatomic, strong) UIView *lineView; @end @implementation UserCell - (void)setupUI { [super setupUI]; AvatarView *avatarView = [AvatarView avatarWithUser:nil]; avatarView.size = CGSizeMake(FIX_SIZE(44), FIX_SIZE(44)); avatarView.layer.cornerRadius = FIX_SIZE(8); avatarView.clipsToBounds = YES; self.avatarView = avatarView; [self.contentView addSubview:avatarView]; self.backgroundColor = self.contentView.backgroundColor = [UIColor clearColor]; UILabel *nickNameLabel = [UILabel mt_titleLabelWithText:@""]; nickNameLabel.font = MT_FONT_REGULAR_SIZE(13); self.nickNameLabel = nickNameLabel; [self addSubview:nickNameLabel]; self.nickNameLabel = nickNameLabel; UILabel *sloganLabel = [UILabel mt_titleLabelWithText:@""]; sloganLabel.font = MT_FONT_REGULAR_SIZE(11); sloganLabel.textColor = CONTENT_COLOR; [self addSubview:sloganLabel]; self.sloganLabel = sloganLabel; WeakSelf(self); PYThemeButton *chatButton = [PYThemeButton smallButtonWithTitle:@"关注" action:^(UIButton * _Nonnull button) { User *user = (User *)weakself.model; if ([button.titleLabel.text isEqualToString:@"关注"]) { [UserService followUserWIthUserID:user.ID completion:^(id _Nullable rsp, NSError * _Nullable error) { if (!error) { if (user.relation == RelationTypeFollower) { user.relation = RelationTypeFriends; } else { user.relation = RelationTypeFollowing; } weakself.model = user; } }]; } else { [PYAppService chatWithUser:user]; } }]; [chatButton setBackgroundColor:COLOR_WITH_RGB_A(0xFFBE00, 0.2)]; [chatButton setTitleColor:THEME_COLOR forState:UIControlStateNormal]; [self.contentView addSubview:chatButton]; self.chatButton = chatButton; self.lineView = [UIView new]; self.lineView.height = 0.5; self.lineView.width = SCREEN_WIDTH; self.lineView.backgroundColor = COLOR_WITH_RGB_A(0xFFFFFF, 0.1); [self.contentView addSubview:self.lineView]; } - (void)layoutSubviews { [super layoutSubviews]; self.avatarView.centerY = self.height * 0.5; self.avatarView.x = FIX_SIZE(15); self.chatButton.right = self.width - self.avatarView.x; self.chatButton.centerY = self.avatarView.centerY; self.nickNameLabel.x = self.avatarView.right + FIX_SIZE(12); self.nickNameLabel.height = self.avatarView.height * 0.5; self.nickNameLabel.y = self.avatarView.y; self.nickNameLabel.width = self.chatButton.x - FIX_SIZE(12) - self.nickNameLabel.x; self.sloganLabel.frame = self.nickNameLabel.frame; self.sloganLabel.y = self.nickNameLabel.bottom; self.lineView.x = self.nickNameLabel.x; self.lineView.bottom = self.height; } - (void)setModel:(User *)model { [super setModel:model]; self.nickNameLabel.text = model.nickname; self.sloganLabel.text = model.introduce; self.avatarView.user = model; BOOL isFollowing = model.isFollowing; [self.chatButton setTitle:isFollowing ? @"聊天" : @"关注" forState:UIControlStateNormal]; if ([self.chatButton.titleLabel.text isEqualToString:@"聊天"]) { [self.chatButton setTitleColor:THEME_COLOR forState:UIControlStateNormal]; [self.chatButton setBackgroundColor:COLOR_WITH_RGB_A(0xFFBE00, 0.2)]; } else { [self.chatButton setTitleColor:COLOR_WITH_RGB(0x040000) forState:UIControlStateNormal]; [self.chatButton setBackgroundColor:THEME_COLOR]; } self.chatButton.hidden = [model isSelf]; } @end