首页 > 其他 > 详细

自定义cell 各个空间的frame设置 QQ为例

时间:2015-03-01 08:58:27      阅读:236      评论:0      收藏:0      [点我收藏+]
 -(void)setMessage:(GYLMessageModel *)message

{

    _message = message;

    

    //屏幕的宽度

    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;

    //间隙

    CGFloat padding = 10;

    //时间

    CGFloat timeX = 0;

    CGFloat timeY = 0;

    CGFloat timeW = screenWidth;

    CGFloat timeH = 30;

    _timeF = CGRectMake(timeX, timeY, timeW, timeH);

    

    

    //2.头像

    CGFloat iconH = 30;

    CGFloat iconW = 30;

    CGFloat iconY = CGRectGetMaxY(_timeF) + padding;

    CGFloat iconX = 0;

    if (GYLMessageModelTypeMe == _message.type) {//自己发的

        //x = 屏幕宽度 - 间隙 - 头像宽度

        iconX = screenWidth - padding - iconW;

        

    }else iconX = padding;

    _iconF = CGRectMake(iconX, iconY, iconW, iconH);

    //3.正文

    NSDictionary * dict = @{NSFontAttributeName :GYLTextFont};

    CGSize maxSize = CGSizeMake(200MAXFLOAT);

    CGSize textSize = [_message.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;

    CGFloat textW = textSize.width;

    CGFloat textH = textSize.height;

    CGFloat textY = iconY;

    CGFloat textX = 0;

    if (GYLMessageModelTypeMe == _message.type) {//自己发的

        // x = 头像x - 间隙 - 文本的宽度

        textX = iconX - padding - textW;

    }else

    {

        //头像的最大的x+ 间隙

        textX = CGRectGetMidX(_iconF) + padding;

    }

    _textF = CGRectMake(textX, textY, textW, textH);

    

    // 4.行高

    CGFloat maxIconY = CGRectGetMaxY(_iconF);

    CGFloat maxTextY = CGRectGetMaxY(_textF);

    

    // _cellHeight = (maxIconY > maxTextY?  (maxIconY + padding) :  (maxIconY + padding));

    _cellHeight = MAX(maxIconY, maxTextY) + padding;

}


自定义cell 各个空间的frame设置 QQ为例

原文:http://blog.csdn.net/guoyule2010/article/details/43997129

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!