2.存放一个cell的高度 // 3.存放着一个数据模型HWStatus
#import <Foundation/Foundation.h>
// 昵称字体 #define HWStatusCellNameFont [UIFont systemFontOfSize:15] // 时间字体 #define HWStatusCellTimeFont [UIFont systemFontOfSize:12] // 来源字体 #define HWStatusCellSourceFont HWStatusCellTimeFont // 正文字体 #define HWStatusCellContentFont [UIFont systemFontOfSize:14]
@class HWStatus;
@interface HWStatusFrame : NSObject @property (nonatomic, strong) HWStatus *status;
/** 原创微博整体 */ @property (nonatomic, assign) CGRect originalViewF; /** 头像 */ @property (nonatomic, assign) CGRect iconViewF; /** 会员图标 */ @property (nonatomic, assign) CGRect vipViewF; /** 配图 */ @property (nonatomic, assign) CGRect photoViewF; /** 昵称 */ @property (nonatomic, assign) CGRect nameLabelF; /** 时间 */ @property (nonatomic, assign) CGRect timeLabelF; /** 来源 */ @property (nonatomic, assign) CGRect sourceLabelF; /** 正文 */ @property (nonatomic, assign) CGRect contentLabelF;
/** cell的高度 */ @property (nonatomic, assign) CGFloat cellHeight; @end
---------------------------HWStatusFrame.m--------------------------------------------- // HWStatusFrame.m // // Created by apple on 14-10-14. // Copyright (c) 2014年 heima. All rights reserved. //
#import "HWStatusFrame.h" #import "HWStatus.h" #import "HWUser.h"
// cell的边框宽度 #define HWStatusCellBorderW 10
@implementation HWStatusFrame
// 通过出入文字的 text 和 font 计算 UILabel 的 CGSize 的方法 - (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxW:(CGFloat)maxW { NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = font; CGSize maxSize = CGSizeMake(maxW, MAXFLOAT); return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size; }
// 通过出入文字的 text 计算 UILabel 的 高度 (最大宽度设置为无限大了) - (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font { return [self sizeWithText:text font:font maxW:MAXFLOAT]; }
- (void)setStatus:(HWStatus *)status { _status = status; HWUser *user = status.user; // cell的宽度 CGFloat cellW = [UIScreen mainScreen].bounds.size.width; /* 原创微博 */ /** 头像 */ CGFloat iconWH = 35; CGFloat iconX = HWStatusCellBorderW; CGFloat iconY = HWStatusCellBorderW; self.iconViewF = CGRectMake(iconX, iconY, iconWH, iconWH);
/** 昵称 */ CGFloat nameX = CGRectGetMaxX(self.iconViewF) + HWStatusCellBorderW; CGFloat nameY = iconY; CGSize nameSize = [self sizeWithText:user.name font:HWStatusCellNameFont]; self.nameLabelF = (CGRect){{nameX, nameY}, nameSize}; /** 会员图标 */ if (user.isVip) { CGFloat vipX = CGRectGetMaxX(self.nameLabelF) + HWStatusCellBorderW; CGFloat vipY = nameY; CGFloat vipH = nameSize.height; & |