码迷,mamicode.com
首页 > 其他好文 > 详细

frame模型

时间:2016-05-29 23:19:14      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

#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;

    

    

}

 

frame模型

标签:

原文地址:http://www.cnblogs.com/qhsblogs/p/5540594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!