新浪微博客户端(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 ...
随机推荐
- 如何下载struts 2及其各个包的作用
一.http://archive.apache.org/dist/struts/library/ 二. struts官网: http://struts.apache.org/ 进入主页后点击" ...
- iOS——百度统计
百度移动统计(http://mtj.baidu.com)是一款专业的移动应用统计分析工具,支持ios和android平台.开发者可以方便地通过嵌入统计SDK,对移动应用进行全方位监测,实时监控产品表现 ...
- HoloLens开发手记 - Unity之Spatial Sounds 空间声音
本文主要讲述如何在项目中使用空间声音特性.我们主要讲述必须的插件组件和Unity声音组件和属性的设置来确保空间声音的实现. Enabling Spatial Sound in Unity 在Unity ...
- 分享:大晚上用自己的锤子手机跨系统刷MIUI,跌宕起伏啊!!
序言: 写这篇博客之前问了一下博客园官方,能不能写关于刷机这一方面的,官方还是比较通情达理的,说技术类没有限制的,那样我就放心的写了.今天早上在博客园中稍微逛了一下,感觉似乎很少有关于刷机这一方面的, ...
- 关于delete 和 new
关于new和delete,有如下代码 // new_test.cpp #include<iostream> using namespace std; class A { public: A ...
- 如何在Mvc 6 中创建 Web Api以及如何脱离IIS实现自我托管
微软推出的Asp.net vNext(asp.net 5.0)的其中的一个目标就是统一mvc 和web api 的框架.接下来我就演示一下一下几个内容 1,怎么在Asp.net mvc 6 中创建简单 ...
- 第三十二课:JSDeferred的性能提速
大家如果看了前面两课,就知道Deferred的静态方法next(next_default)是用setTimeout实现的(有浏览器最小时钟间隔).但是实现这种异步操作,可以有很多种方法.JSDefer ...
- DOM(七)使用DOM控制表格
表格的css控制就先不说了,首先分享下表格常用的DOM 表格添加操作的方法常用的为insertRow()和insertCell()方法. row是从零开始计算起的,例如: var oTr = docu ...
- android常用的弹出提示框
我们在平时做开发的时候,免不了会用到各种各样的对话框,相信有过其他平台开发经验的朋友都会知道,大部分的平台都只提供了几个最简单的实现,如果我们想实现自己特定需求的对话框,大家可能首先会想到,通过继承等 ...
- Daily Scrum – 1/4
Meeting Minutes 大家讨论了一下作业的内容,以及用户的反馈,商量了一下长期计划(naive)的完成方式. 好像有些时候用户测试的时候会崩溃,不过我们自己用的时候一直没有出现过,分析可能是 ...