标签:
#import "CZWeiboFrame.h"
#import "CZWeibo.h"
@implementation CZWeiboFrame
#define KPadding 10
#define KIconImageViewWH 30
#define KVipImageViewWH 15
#define KPicImageViewWH 70
-(void)setWeibo:(CZWeibo *)weibo
{
_weibo = weibo;
//1.用户头像的frame;
self.iconImageViewFrame = CGRectMake(KPadding, KPadding, KIconImageViewWH, KIconImageViewWH);
//2.设置用户名字的frame
//2.1 获取字符串信息
NSString *userNameStr = weibo.name;
//2.2根据字符串内容计算宽高
CGRect userNameBouns = [userNameStr boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil];
//设置用户名字的frame
self.userNameLabelFrame = CGRectMake(CGRectGetMaxX(self.iconImageViewFrame)+KPadding, CGRectGetMidY(self.iconImageViewFrame), userNameBouns.size.width, userNameBouns.size.height);
/**
* vip图标的frame
*/
self.vipImageViewFrame = CGRectMake(CGRectGetMaxX(self.userNameLabelFrame)+KPadding, CGRectGetMidY(self.iconImageViewFrame), KVipImageViewWH, KVipImageViewWH);
//4.描述信息的frame
//根据文字内容计算显示的宽高
NSString *messageStr = weibo.text;
UIScreen *screen = [UIScreen mainScreen];
CGFloat sizeW = screen.bounds.size.width-2*KPadding;
CGRect messageBouns = [messageStr boundingRectWithSize:CGSizeMake(sizeW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil];
self.messageLabelFrame = CGRectMake(KPadding, CGRectGetMaxY(self.iconImageViewFrame)+2*KPadding, messageBouns.size.width, messageBouns.size.height);
/**
* 内部图片的frame‘
*/
if(weibo.picture.length>0)
{
self.pictureImageViewFrame = CGRectMake(KPadding, CGRectGetMaxY(self.messageLabelFrame)+2*KPadding, KPicImageViewWH, KPicImageViewWH);
}
/**
* 获取行高
*/
CGFloat messageLabelMaxY = CGRectGetMaxY(self.messageLabelFrame)+KPadding;
CGFloat picImageViewMaxY = CGRectGetMaxY(self.pictureImageViewFrame)+KPadding;
//判断文字和图片的
self.rowHight = messageLabelMaxY>picImageViewMaxY?messageLabelMaxY:picImageViewMaxY;
}
标签:
原文地址:http://www.cnblogs.com/qhsblogs/p/5540594.html