新浪微博客户端(22)-创建微博Cell
DJStatusCell.h
#import <UIKit/UIKit.h> @class DJStatusCellFrame; @interface DJStatusCell : UITableViewCell /** DJStatusCell 的默认构造方法 */ + (instancetype)cellWithTableView:(UITableView *)tableView; @property (nonatomic,strong) DJStatusCellFrame *statusFrame; @end
DJStatusCell.m
#import "DJStatusCell.h" #import "DJStatusCellFrame.h" #import "DJStatus.h" #import "DJUser.h" #import "UIImageView+WebCache.h" @interface DJStatusCell() //============================== 原创微博部分 ======================================== /** 原创微博整体 */ @property (nonatomic,weak) UIView *originalView; /** 头像 */ @property (nonatomic,weak) UIImageView *iconView; /** 会员标志 */ @property (nonatomic,weak) UIImageView *vipView; /** 微博图片 */ @property (nonatomic,weak) UIImageView *photoView; /** 昵称 */ @property (nonatomic,weak) UILabel *nameLabel; /** 发布时间 */ @property (nonatomic,weak) UILabel *timeLabel; /** 微博来源 */ @property (nonatomic,weak) UILabel *sourceLabel; /** 微博内容 */ @property (nonatomic,weak) UILabel *contentLabel; //============================== 原创微博部分 ======================================== @end @implementation DJStatusCell + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *ID = @"status"; DJStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[DJStatusCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } return cell; } /** cell的默认初始化方法,此方法只会被调用一次 */ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // 原创微博整体 UIView *originalView = [[UIView alloc] init]; [self.contentView addSubview:originalView]; self.originalView = originalView; // 头像 UIImageView *iconView = [[UIImageView alloc] init]; [self.originalView addSubview:iconView]; self.iconView = iconView; // 会员标志 UIImageView *vipView = [[UIImageView alloc] init]; [self.originalView addSubview:vipView]; self.vipView = vipView; // 微博图片 UIImageView *photoView = [[UIImageView alloc] init]; [self.originalView addSubview:photoView]; self.photoView = photoView; // 昵称 UILabel *nameLabel = [[UILabel alloc] init]; [self.originalView addSubview:nameLabel]; self.nameLabel = nameLabel; // 发布时间 UILabel *timeLabel = [[UILabel alloc] init]; [self.originalView addSubview:timeLabel]; self.timeLabel = timeLabel; // 微博来源 UILabel *sourceLabel = [[UILabel alloc] init]; [self.originalView addSubview:sourceLabel]; self.sourceLabel = sourceLabel; // 微博内容 UILabel *contentLabel = [[UILabel alloc] init]; [self.originalView addSubview:contentLabel]; self.contentLabel = contentLabel; } return self; } - (void)setStatusFrame:(DJStatusCellFrame *)statusFrame { _statusFrame = statusFrame; DJStatus *status = statusFrame.status; DJUser *user = status.user; /* 设置当前View的Frame */ // 原创微博整体 self.originalView.frame = statusFrame.originalViewF; // 头像 self.iconView.frame = statusFrame.iconViewF; [self.iconView sd_setImageWithURL:[NSURL URLWithString:user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_small"]]; // 会员标志 self.vipView.frame = statusFrame.vipViewF; [self.vipView setImage:[UIImage imageNamed:@"common_icon_membership_level1"]]; // 微博图片 self.photoView.frame = statusFrame.photoViewF; // 昵称 self.nameLabel.frame = statusFrame.nameLabelF; self.nameLabel.text = user.name; // 发布时间 self.timeLabel.frame = statusFrame.timeLabelF; // 微博来源 self.sourceLabel.frame = statusFrame.sourceLabelF; // 微博内容 self.contentLabel.frame = statusFrame.contentLabelF; self.contentLabel.text = status.text; } @end
DJStatusCellFrame.h
#import <Foundation/Foundation.h> @class DJStatus; @interface DJStatusCellFrame : NSObject /** 微博数据实体 */ @property (nonatomic,strong) DJStatus *status; /** 原创微博整体的Frame */ @property (nonatomic,assign) CGRect originalViewF; /** 头像的Frame */ @property (nonatomic,assign) CGRect iconViewF; /** 会员标志的Frame */ @property (nonatomic,assign) CGRect vipViewF; /** 微博图片的Frame */ @property (nonatomic,assign) CGRect photoViewF; /** 昵称的Frame */ @property (nonatomic,assign) CGRect nameLabelF; /** 发布时间的Frame */ @property (nonatomic,assign) CGRect timeLabelF; /** 微博来源的Frame */ @property (nonatomic,assign) CGRect sourceLabelF; /** 微博内容的Frame */ @property (nonatomic,assign) CGRect contentLabelF; /** 当前微博的高度 */ @property (nonatomic,assign) CGFloat cellHeight; @end
DJStatusCellFrame.m
#import "DJStatusCellFrame.h" @implementation DJStatusCellFrame - (void)setStatus:(DJStatus *)status { _status = status; } @end
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库