DJStatusCellFrame.m

#import "DJStatusCellFrame.h"
#import "DJStatus.h"
#import "DJUser.h" @implementation DJStatusCellFrame - (void)setStatus:(DJStatus *)status { _status = status; DJUser *user = status.user; /* 计算控件Frame */
CGFloat cellW = [UIScreen mainScreen].bounds.size.width; // 头像
CGFloat iconW = ;
CGFloat iconH = ;
CGFloat iconX = DJStatusCellMargin;
CGFloat iconY = DJStatusCellMargin;
self.iconViewF = CGRectMake(iconX, iconY, iconW, iconH); // 昵称
CGFloat nameX = CGRectGetMaxX(self.iconViewF) + DJStatusCellMargin;
CGFloat nameY = iconY + DJStatusCellMargin2;
CGSize nameSize = [user.name sizeWithFont:DJStatusCellNameFont];
self.nameLabelF = (CGRect){{nameX,nameY},nameSize}; // 会员标志
if (user.isVip) { // 如果用户是会员,才计算会员图标的frame
CGFloat vipX = CGRectGetMaxX(self.nameLabelF) + DJStatusCellMargin;
CGFloat vipY = nameY;
CGFloat vipW = ;
CGFloat vipH = nameSize.height;
self.vipViewF = CGRectMake(vipX, vipY, vipW, vipH);
} // 时间
CGFloat timeX = nameX;
CGFloat timeY = CGRectGetMaxY(self.nameLabelF) + DJStatusCellMargin2;
CGSize timeSize = [status.created_at sizeWithFont:DJStatusCellTimeFont];
self.timeLabelF = (CGRect){{timeX,timeY},timeSize}; // 来源
CGFloat sourceX = CGRectGetMaxX(self.timeLabelF) + DJStatusCellMargin;
CGFloat sourceY = timeY;
CGSize sourceSize = [status.source sizeWithFont:DJStatusCellSourceFont];
self.sourceLabelF = (CGRect){{sourceX,sourceY},sourceSize}; // 内容
CGFloat contentX = iconX;
CGFloat contentY = MAX(CGRectGetMaxY(self.iconViewF), CGRectGetMaxY(self.timeLabelF)) + DJStatusCellMargin;
CGFloat cellMaxW = cellW - * DJStatusCellMargin;
CGSize contentSize = [status.text sizeWithFont:DJStatusCellContentFont maxW:cellMaxW];
self.contentLabelF = (CGRect){{contentX,contentY},contentSize}; // 原创微博整体
CGFloat originalX = ;
CGFloat originalY = ;
CGFloat originalW = cellW;
CGFloat originalH = CGRectGetMaxY(self.contentLabelF) + DJStatusCellMargin;
self.originalViewF = CGRectMake(originalX, originalY, originalW, originalH); self.cellHeight = originalH; } @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;
// originalView.backgroundColor = DJRandomColor; // 头像
UIImageView *iconView = [[UIImageView alloc] init];
[self.originalView addSubview:iconView];
self.iconView = iconView; // 昵称
UILabel *nameLabel = [[UILabel alloc] init];
[self.originalView addSubview:nameLabel];
self.nameLabel = nameLabel;
self.nameLabel.font = DJStatusCellNameFont;
// self.nameLabel.backgroundColor = DJRandomColor; // 会员标志
UIImageView *vipView = [[UIImageView alloc] init];
[self.originalView addSubview:vipView];
self.vipView = vipView;
self.vipView.contentMode = UIViewContentModeCenter;
// self.vipView.backgroundColor = DJRandomColor; // 发布时间
UILabel *timeLabel = [[UILabel alloc] init];
[self.originalView addSubview:timeLabel];
self.timeLabel = timeLabel;
timeLabel.font = DJStatusCellTimeFont; // 微博来源
UILabel *sourceLabel = [[UILabel alloc] init];
[self.originalView addSubview:sourceLabel];
self.sourceLabel = sourceLabel;
sourceLabel.font = DJStatusCellSourceFont; // 微博内容
UILabel *contentLabel = [[UILabel alloc] init];
[self.originalView addSubview:contentLabel];
self.contentLabel = contentLabel;
contentLabel.font = DJStatusCellContentFont;
contentLabel.numberOfLines = ; // 设置微博内容为多行显示 // 微博图片
UIImageView *photoView = [[UIImageView alloc] init];
[self.originalView addSubview:photoView];
self.photoView = photoView; }
return self; } - (void)setStatusFrame:(DJStatusCellFrame *)statusFrame { _statusFrame = statusFrame; DJStatus *status = statusFrame.status;
DJUser *user = status.user; /* 设置当前View的Frame */ // 头像
self.iconView.frame = statusFrame.iconViewF;
[self.iconView sd_setImageWithURL:[NSURL URLWithString:user.profile_image_url] placeholderImage:[UIImage imageNamed:@"avatar_default_small"]]; // 昵称
self.nameLabel.frame = statusFrame.nameLabelF;
self.nameLabel.text = user.name; // 会员标志
if (user.isVip) {
self.vipView.hidden = NO;
self.vipView.frame = statusFrame.vipViewF;
NSString *mbrank = [NSString stringWithFormat:@"common_icon_membership_level%d",user.mbrank];
[self.vipView setImage:[UIImage imageNamed:mbrank]];
self.nameLabel.textColor = [UIColor orangeColor];
} else {
self.vipView.hidden = YES;
self.nameLabel.textColor = [UIColor blackColor];
} // 发布时间
self.timeLabel.frame = statusFrame.timeLabelF;
self.timeLabel.text = status.created_at; // 微博来源
self.sourceLabel.frame = statusFrame.sourceLabelF;
self.sourceLabel.text = status.source; // 微博内容
self.contentLabel.frame = statusFrame.contentLabelF;
self.contentLabel.text = status.text; // 微博图片
self.photoView.frame = statusFrame.photoViewF; // 原创微博整体
self.originalView.frame = statusFrame.originalViewF; } @end

最终效果:

新浪微博客户端(23)-计算Cell内控件的frame的更多相关文章

  1. WinForm容器内控件批量效验是否同意为空?设置是否仅仅读?设置是否可用等方法分享

    WinForm容器内控件批量效验是否同意为空?设置是否仅仅读?设置是否可用等方法分享 在WinForm程序中,我们有时须要对某容器内的全部控件做批量操作.如批量推断是否同意为空?批量设置为仅仅读.批量 ...

  2. WinForm容器内控件批量效验是否允许为空?设置是否只读?设置是否可用等方法分享

    WinForm容器内控件批量效验是否允许为空?设置是否只读?设置是否可用等方法分享 在WinForm程序中,我们有时需要对某容器内的所有控件做批量操作.如批量判断是否允许为空?批量设置为只读.批量设置 ...

  3. Repeater事件OnItemCommand取得行内控件

    记录一下,主要是这句:TextBox txtNum = e.Item.FindControl("txtNum") as TextBox; Repeater真是太强了,太灵活.除了R ...

  4. 2.23 js处理日历控件(修改readonly属性)

    2.23 js处理日历控件(修改readonly属性) 前言    日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如 ...

  5. iOS开发UI基础—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

  6. 重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter; 容器控件: Border, Viewbox, Popup

    原文:重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter ...

  7. 与导航栏下控件的frame相关的edgesForExtendedLayout、translucent、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets等几个属性的详解

    在引入了导航控制器UINavigationController和分栏控制器UITabBarController之后,我们在设置控件的frame的时候就需要注意避开导航栏UINavigationBar ...

  8. IOS 设置子控件的frame(layoutSubviews and awakeFromNib)

      如果控件是通过xib或者storyboard创建出来的就会调用该方法 - (void)awakeFromNib :该方法只会调用一次 // 如果控件是通过xib或者storyboard创建出来的就 ...

  9. iOS开发UI篇—手写控件,frame,center和bounds属性

    iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...

随机推荐

  1. Ubuntu 14.04 下安装google的浏览器——Chrome

    小编用过好多浏览器,但最后还是选择Chrome, 因为这款浏览器确实做的不错,可是Ubuntu下自带的是火狐,因此小编在这里和大家分享一下如何在Ubuntu下安装chrome浏览器 工具/原料   安 ...

  2. 如何优雅的写一篇安利文-以Sugar ORM为例

    前言 我最近喜欢把写的十分优美的技术文章叫做安利文.首先,文章必须是原创而非软广:其次,阅读之后不仅能快速吸纳技术要点并入门开发,还能感同身受的体会作者热情洋溢的赞美和急于分享心得体验的心情,让人感觉 ...

  3. PHP+微信分享自定义小图标

    微信分享以后的小图标如下图: <script>document.addEventListener('WeixinJSBridgeReady', function onBridgeReady ...

  4. Git.Framework 框架随手记--ORM新增操作

    本篇主要记录具体如何新增数据,废话不多说,开始进入正文. 一. 生成工程结构 上一篇已经说到了如何生成工程结构,这里在累述一次. 1. 新建项目总体结构 使用VS新建项目结构,分层结构可以随意.我们使 ...

  5. 公司ERP系统重构那些事

    记一次会议,我提出插件化的想法,有支持也有反对,其中"系统架构师"表示插件化后的项目没什么意义,今天来讨论项目是否需要插件化的一些观点. 项目背景 公司内部"ERP&qu ...

  6. SQL温故系列两篇(二)

    .Sql 插入语句得到自动生成的递增的ID值 Insert into Table(name,des,num) values(’ltp’,’thisisbest’,10); Select @@ident ...

  7. 重构笔记---MEF框架(上)

    概述 这篇文章的目的是简要分析对比MAF和MEF,并详细举出MEF设计中的细节和扩展上的细节,达到让读者能实际操作的目的.其中,MAF的设计会附上我的代码,其实就是官方的代码我自己手动联系了一遍,但还 ...

  8. jQuery应用之(二)使用jQuery管理选择结果(荐)

    使用jQuery选择出来的元素与数组非常类似,可以通过jQuery提供的一系列方法对其进行处理,包括长度.查找某个元素,截取某个段落等. 1.获取元素的个数. 在jQuery中可以通过size()方法 ...

  9. AngularJS开发指南16:AngularJS构建大型Web应用详解

    AngularJS是由Google创建的一种JS框架,使用它可以扩展应用程序中的HTML功能,从而在web应用程序中使用HTML声明动态内容.在该团队工作的软件工程师Brian Ford近日撰写了一篇 ...

  10. http状态码介绍

    基本涵盖了所有问题HTTP 400 – 请求无效HTTP 401.1 – 未授权:登录失败HTTP 401.2 – 未授权:服务器配置问题导致登录失败HTTP 401.3 – ACL 禁止访问资源HT ...