123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // XYPersinalContentTableViewCell.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2019/12/21.
- // Copyright © 2019 翟玉磊. All rights reserved.
- //
- #import "XYPersinalContentTableViewCell.h"
- #import "XYPersonalCenterListModel.h"
- @interface XYPersinalContentTableViewCell ()
- /// cell的白底背景
- @property (nonatomic, readwrite, strong) UIView *infoView;
- /// icon
- @property (nonatomic, readwrite, strong) UIImageView *titleImageView;
- /// 标题
- @property (nonatomic, readwrite, strong) UILabel *titleLabel;
- /// 更多图片
- @property (nonatomic, readwrite, strong) UIImageView *moreImageView;
- /// 附加内容 显示在靠右变
- @property (nonatomic, readwrite, strong) UILabel *contentLabel;
- /// 附加内容的右边和父view的约束
- @property (nonatomic, readwrite, strong) MASConstraint *contentRightConstraint;
- /// 附加内容 显示在contentLabel左边
- @property (nonatomic, strong) UIImageView *contentImageView;
- @end
- @implementation XYPersinalContentTableViewCell
- #pragma mark - Public Method
- + (instancetype)cellWithTableView:(UITableView *)tableView {
- static NSString * const cellId = @"XYPersinalContentTableViewCell";
- XYPersinalContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
- if (cell == nil) {
- cell = [[XYPersinalContentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return cell;
- }
- - (void)configureModel:(XYPersonalCenterListModel *)model {
- self.titleImageView.image = ImageNamed(model.iconName);
- self.titleLabel.text = model.title;
- self.moreImageView.hidden = !model.isShowMoreImage;
- self.contentLabel.text = model.content;
- [self.contentImageView sd_setImageWithURL:UrlForString(model.imageContent) placeholderImage:nil];
-
- self.contentRightConstraint.equalTo(@(model.isShowMoreImage?(-(15.0f + 6.0f + 4.0f)):-15.0f));
- if ([model.title isEqualToString:@"我的芝麻"]) {
- self.titleLabel.textColor = Color_TextRed;
- }else {
- self.titleLabel.textColor = Color_TextFont;
- }
- }
- - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
- if (indexPath.row == 0 && rows == 1) {
- // 说明只有一个cell
- [self.infoView addViewBorderWithCorners:UIRectCornerAllCorners color:Color_Clear redian:8];
- }else if (indexPath.row == 0 && rows != 1) {
- // 说明是第一个cell且section下不止一个cell
- [self.infoView addViewBorderWithCorners:UIRectCornerTopLeft|UIRectCornerTopRight color:Color_Clear redian:8];
- }else if (indexPath.row == rows && rows != 1) {
- // 说明是最后一个cell且section下不止一个cell
- [self.infoView addViewBorderWithCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight color:Color_Clear redian:8];
- }else {
- // 中间的cell重置边框
- [self.infoView addViewBorder:Color_Clear redian:0];
- }
- }
- #pragma mark - 初始化
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
-
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- // 初始化
- [self _setup];
-
- // 创建自控制器
- [self _setupSubViews];
-
- // 布局子控件
- [self _makeSubViewsConstraints];
- }
- return self;
- }
- #pragma mark - 事件处理Or辅助方法
- #pragma mark - Private Method
- - (void)_setup{
- self.backgroundColor = Color_Clear;
- }
- #pragma mark - 创建子控件
- - (void)_setupSubViews{
- [self.contentView addSubview:self.infoView];
- [self.infoView addSubview:self.titleImageView];
- [self.infoView addSubview:self.titleLabel];
- [self.infoView addSubview:self.moreImageView];
- [self.infoView addSubview:self.contentLabel];
- [self.infoView addSubview:self.contentImageView];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
- [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(0.0f);
- make.right.equalTo(self.contentView).offset(0.0f);
- make.top.bottom.equalTo(self.contentView);
- }];
- [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.infoView).offset(16.0f);
- make.centerY.equalTo(self.infoView);
- make.width.height.equalTo(@18.0f);
- }];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.titleImageView.mas_right).offset(12.0f);
- make.centerY.equalTo(self.infoView);
- make.right.equalTo(self.contentLabel.mas_left).offset(-10.0f);
- }];
- [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.infoView).offset(-15.0f);
- make.centerY.equalTo(self.infoView);
- make.width.equalTo(@6.0f);
- make.height.equalTo(@10.0f);
- }];
- [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- self.contentRightConstraint = make.right.equalTo(self.infoView).offset(-(15.0f + 12.0f + 10.0f));
- make.centerY.equalTo(self.infoView);
- }];
- [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentLabel.mas_left).offset(-4.0f);
- make.centerY.equalTo(self.infoView);
- make.width.height.equalTo(@20.0f);
- }];
- }
- - (UIView *)infoView {
- if (!_infoView) {
- _infoView = [UIView new];
- // 因为要设置边框索引需要先有frame
- _infoView.frame = self.bounds;
- _infoView.backgroundColor = Color_White;
- }
- return _infoView;;
- }
- - (UIImageView *)titleImageView {
- if (!_titleImageView) {
- _titleImageView = [UIImageView new];
- }
- return _titleImageView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font(15)];
- }
- return _titleLabel;
- }
- - (UIImageView *)moreImageView {
- if (!_moreImageView) {
- _moreImageView = [UIImageView new];
- _moreImageView.image = arrowMore();
- }
- return _moreImageView;
- }
- - (UILabel *)contentLabel {
- if (!_contentLabel) {
- _contentLabel = [UILabel createLabelTextColor:Color_TextGray fount:Font(12)];
- _contentLabel.textAlignment = NSTextAlignmentRight;
- }
- return _contentLabel;
- }
- - (UIImageView *)contentImageView {
- if (_contentImageView == nil) {
- _contentImageView = [UIImageView new];
- }
- return _contentImageView;
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|