美文网首页
关于 UITableViewCell 的一些设置

关于 UITableViewCell 的一些设置

作者: 努力奔跑的小男孩 | 来源:发表于2017-09-27 13:39 被阅读5次

    | 用到的一些扩展类
    NSDate 的扩展(Category) 时间处理 针对评论时间处理
    UIImage 的扩展(Category)

    .h 文件

    #import <UIKit/UIKit.h>
    #import "YYTopicModel.h"
    //@class YYTopicModel;
    @interface YYWordCell : UITableViewCell
    @property(nonatomic, strong) YYTopicModel *model;// 模型
    @end
    

    .m文件

    #import "YYWordCell.h"
    #import "UIImage+YYExtension.h" // 引入头文件
    #import "NSDate+YYExtension.h" // 引入头文件
    @interface YYWordCell()
    
    @property (weak, nonatomic) IBOutlet UIImageView *iconImage; // 头像
    @property (weak, nonatomic) IBOutlet UILabel *nickName;// 昵称
    @property (weak, nonatomic) IBOutlet UILabel *timeLabel; // 时间
    @property (weak, nonatomic) IBOutlet UIButton *dingBtn; // 顶
    @property (weak, nonatomic) IBOutlet UIButton *caiBtn; // 踩
    @property (weak, nonatomic) IBOutlet UIButton *shareBtn; // 分享
    @property (weak, nonatomic) IBOutlet UIButton *commentBtn; // 评论
    
    
    @end
    
    @implementation YYWordCell
    
    // 修改 cell 的上下左右的距离
    - (void)setFrame:(CGRect)frame{
        frame.origin.y += 10;
        frame.size.height -= 10;
        frame.size.width -= 20;
        frame.origin.x += 10;
        [super setFrame:frame];
    }
    
    - (void)awakeFromNib {
        [super awakeFromNib];
        // 给cell 添加背景图
        UIImageView *bgImage = [[UIImageView alloc]initWithImage:[UIImage imageWithOriginalName:@"mainCellBackground"].resizbleImage];
        self.backgroundView = bgImage;
        
    }
    
    - (void)setModel:(YYTopicModel *)model{
        _model = model;
        // 拿出子控件设置数据
        
        [self.iconImage sd_setImageWithURL:[NSURL URLWithString:model.profile_image] placeholderImage:[UIImage imageWithOriginalName:@"defaultUserIcon"]];
        self.nickName.text = model.name;
        self.timeLabel.text = [NSDate yyDateWith:model.create_time];
        // 设置工具条
        [self.dingBtn setTitle:[NSString stringWithFormat:@"%zd",model.ding] forState:UIControlStateNormal];
        [self.caiBtn setTitle:[NSString stringWithFormat:@"%zd",model.cai] forState:UIControlStateNormal];
        [self.shareBtn setTitle:[NSString stringWithFormat:@"%zd",model.repost] forState:UIControlStateNormal];
        [self.commentBtn setTitle:[NSString stringWithFormat:@"%zd",model.comment] forState:UIControlStateNormal];
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        [super setSelected:selected animated:animated];
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:关于 UITableViewCell 的一些设置

          本文链接:https://www.haomeiwen.com/subject/ayxuextx.html