新浪微博客户端(23)-计算Cell内控件的frame
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的更多相关文章
- WinForm容器内控件批量效验是否同意为空?设置是否仅仅读?设置是否可用等方法分享
WinForm容器内控件批量效验是否同意为空?设置是否仅仅读?设置是否可用等方法分享 在WinForm程序中,我们有时须要对某容器内的全部控件做批量操作.如批量推断是否同意为空?批量设置为仅仅读.批量 ...
- WinForm容器内控件批量效验是否允许为空?设置是否只读?设置是否可用等方法分享
WinForm容器内控件批量效验是否允许为空?设置是否只读?设置是否可用等方法分享 在WinForm程序中,我们有时需要对某容器内的所有控件做批量操作.如批量判断是否允许为空?批量设置为只读.批量设置 ...
- Repeater事件OnItemCommand取得行内控件
记录一下,主要是这句:TextBox txtNum = e.Item.FindControl("txtNum") as TextBox; Repeater真是太强了,太灵活.除了R ...
- 2.23 js处理日历控件(修改readonly属性)
2.23 js处理日历控件(修改readonly属性) 前言 日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如 ...
- iOS开发UI基础—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
- 重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter; 容器控件: Border, Viewbox, Popup
原文:重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter ...
- 与导航栏下控件的frame相关的edgesForExtendedLayout、translucent、extendedLayoutIncludesOpaqueBars、automaticallyAdjustsScrollViewInsets等几个属性的详解
在引入了导航控制器UINavigationController和分栏控制器UITabBarController之后,我们在设置控件的frame的时候就需要注意避开导航栏UINavigationBar ...
- IOS 设置子控件的frame(layoutSubviews and awakeFromNib)
如果控件是通过xib或者storyboard创建出来的就会调用该方法 - (void)awakeFromNib :该方法只会调用一次 // 如果控件是通过xib或者storyboard创建出来的就 ...
- iOS开发UI篇—手写控件,frame,center和bounds属性
iOS开发UI基础—手写控件,frame,center和bounds属性 一.手写控件 1.手写控件的步骤 (1)使用相应的控件类创建控件对象 (2)设置该控件的各种属性 (3)添加控件到视图中 (4 ...
随机推荐
- 北京联想招聘-Android高级工程师(5-7年) 加入qq 群:220486180 或者直接在此 留言咨询
Job ID #: 47979 Position Title: 高级Android开发工程师 Location: CHN-Beijing Functional Area: Research/Devel ...
- Linux(9.14-9.20)学习笔记
实验一 Linux系统简介 一.Linux 为何物 Linux 就是一个操作系统,Linux 也就是系统调用和内核那两层. 二.Linux 历史简介 操作系统始于二十世纪 50 年代,当时的操作系统能 ...
- 实现checkbox组件化(Component)
之前我写了一篇自定义checkbox的文章,通过css3实现自定义的checkbox,并没有使用当今流行的Reactjs, 或者Vuejs之类的进行组件化.但是很显然,这样封装的checkbox组件复 ...
- Unity发送参数给iOSNative并响应
unity想要给iOS客户端发送通知并相应.语言太苍白直接上代码. unity端创建两个C#文件 1.触发cs这个不用多说,大家估计都懂. using UnityEngine; using Syste ...
- 无光驱安装原版 windows server2008,win7 的方法,64位的。
这几天要对一台服务器进行安装 windows server2008的系统,64位.尼玛在网上买了一个光驱迟迟不到所以只能用U盘来了 以前安装ghost的系统U盘分分钟搞定.安装原版的iso文件遇到了一 ...
- 删除 windows 下 node_modules 过深的目录
本文同步自我的个人博客:http://www.52cik.com/2015/11/13/node-modules-del.html 说到 node 的模块,确实既好用又蛋疼.相信无数人吐槽 node_ ...
- threejs构建web三维视图入门教程
本文是一篇简单的webGL+threejs构建web三维视图的入门教程,你可以了解到利用threejs创建简单的三维图形,并且控制图形运动.若有不足,欢迎指出. 本文使用的框架是three.js gi ...
- 关于RESTFul初步理解
RESTFul架构:是目前最流行的一种互联网软件架构.它结构清晰.符合标准.易于理解.扩展方便,所以正得到越来越多网站的采用. 即:Representational State Transfer 表现 ...
- ZOJ 3201 树形dp+背包(简单题)
#include<cstdio> #include<vector> #include<cstring> #include<iostream> using ...
- Java 使用正则表达式
用正则表达式来处理掉内容中的特定字符,下面的代码为,去掉P标签中的属性width 设置.将P标签处理后在拼接成字符串 /** * 给 P 标签去掉width 样式设置 * @param content ...