---------- CZStatuse.h ----------
#import <Foundation/Foundation.h>
@interface CZStatuse : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *icon;
@property (nonatomic, copy) NSString *text;
@property (nonatomic, copy) NSString *picture;
@property (nonatomic, assign) BOOL vip;
- (instancetype)initWithDict:(NSDictionary *)dict;
+ (instancetype)statuseWithDict:(NSDictionary *)dict;
@end
---------- CZStatuse.m ----------
#import "CZStatuse.h"
@implementation CZStatuse
- (instancetype)initWithDict:(NSDictionary *)dict
{
if (self = [super init])
{
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
+ (instancetype)statuseWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
@end
---------- CZStatuseFrame.h ----------
#import <Foundation/Foundation.h>
#define CZNameFont [UIFont systemFontOfSize:14]
#define CZTextFont [UIFont systemFontOfSize:14]
@class CZStatuse;
@interface CZStatuesFrame : NSObject
@property (nonatomic, assign, readonly) CGRect iconF;
@property (nonatomic, assign, readonly) CGRect nameF;
@property (nonatomic, assign, readonly) CGRect textF;
@property (nonatomic, assign, readonly) CGRect pictureF;
@property (nonatomic, assign, readonly) CGRect vipF;
@property (nonatomic, assign) CGFloat cellHeight;
@property (nonatomic, strong) CZStatuse *statuse;
@end
---------- CZStatuseFrame.m ----------
#import "CZStatuesFrame.h"
#import "CZStatuse.h"
@implementation CZStatuesFrame
- (void)setStatuse:(CZStatuse *)statuse
{
_statuse = statuse;
CGFloat padding = 10;
CGFloat iconX = padding;
CGFloat iconY = padding;
CGFloat iconW = 30;
CGFloat iconH = 30;
_iconF = CGRectMake(iconX, iconY, iconW, iconH);
CGSize nameSize = [self sizeWithText:_statuse.name andFont:CZNameFont andMaxSize:CGSizeMake(MAXFLOAT, MAXFLOAT)];
CGFloat nameX = CGRectGetMaxX(self.iconF) + padding;
CGFloat nameY = iconY + (iconH - nameSize.height) * 0.5;
_nameF = CGRectMake(nameX, nameY, nameSize.width, nameSize.height);
CGFloat vipX = CGRectGetMaxX(self.nameF) + padding;
CGFloat vipY = nameY;
CGFloat vipW = 14;
CGFloat vipH = 14;
_vipF = CGRectMake(vipX, vipY, vipW, vipH);
CGFloat textX = iconX;
CGFloat textY = CGRectGetMaxY(self.iconF) + padding;
CGSize textSize = [self sizeWithText:_statuse.text andFont:CZTextFont andMaxSize:CGSizeMake(300, MAXFLOAT)];
_textF = CGRectMake(textX, textY, textSize.width, textSize.height);
if (_statuse.picture)
{
CGFloat pictureX = textX;
CGFloat pictureY = CGRectGetMaxY(self.textF) + padding;
CGFloat pictureW = 100;
CGFloat pictureH = 100;
_pictureF = CGRectMake(pictureX, pictureY, pictureW, pictureH);
self.cellHeight = CGRectGetMaxY(self.pictureF) + padding;
}
else
{
self.cellHeight = CGRectGetMaxY(self.textF) + padding;
}
}
- (CGSize)sizeWithText:(NSString *)text andFont:(UIFont *)font andMaxSize:(CGSize)maxSize
{
NSDictionary *attrs = @{NSFontAttributeName : font};
CGSize size = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
return size;
}
@end
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);