---------- CZStatuesCell.h ----------
#import <UIKit/UIKit.h>
@class CZStatuesFrame;
@interface CZStatuesCell : UITableViewCell
@property (nonatomic, strong) CZStatuesFrame *statuesFrame;
@property (nonatomic, assign) CGFloat cellHeight;
+ (instancetype)cellWithTableView:(UITableView *)tableView;
@end
---------- CZStatuesCell.m ----------
#import "CZStatuesCell.h"
#import "CZStatuse.h"
#import "CZStatuesFrame.h"
@interface CZStatuesCell ()
@property (nonatomic, weak) UIImageView *iconView;
@property (nonatomic, weak) UILabel *nameView;
@property (nonatomic, weak) UIImageView *vipView;
@property (nonatomic, weak) UILabel *textView;
@property (nonatomic, weak) UIImageView *pictureView;
@end
@implementation CZStatuesCell
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString * ID = @"weibo";
CZStatuesCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil)
{
cell = [[CZStatuesCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
[self makeView];
}
return self;
}
- (void)makeView
{
UIImageView *iconView = [[UIImageView alloc] init];
[self.contentView addSubview:iconView];
self.iconView = iconView;
UILabel *nameView = [[UILabel alloc] init];
[self.contentView addSubview:nameView];
nameView.font = CZNameFont;
self.nameView = nameView;
UIImageView *vipView = [[UIImageView alloc] init];
vipView.image = [UIImage imageNamed:@"vip"];
[self.contentView addSubview:vipView];
self.vipView = vipView;
UILabel *textView = [[UILabel alloc] init];
textView.numberOfLines = 0;
textView.font = CZTextFont;
[self.contentView addSubview:textView];
self.textView = textView;
UIImageView * pictureView = [[UIImageView alloc] init];
[self.contentView addSubview:pictureView];
self.pictureView = pictureView;
}
- (void)setStatuesFrame:(CZStatuesFrame *)statuesFrame
{
_statuesFrame = statuesFrame;
[self settingData];
[self settingFrame];
}
- (void)settingData
{
CZStatuse *statue = self.statuesFrame.statuse;
self.iconView.image = [UIImage imageNamed:statue.icon];
self.nameView.text = statue.name;
if (statue.vip)
{
self.vipView.hidden = NO;
self.nameView.textColor = [UIColor redColor];
}
else
{
self.vipView.hidden = YES;
self.nameView.textColor = [UIColor blackColor];
}
self.textView.text = statue.text;
if (statue.picture)
{
self.pictureView.hidden = NO;
self.pictureView.image = [UIImage imageNamed:statue.picture];
}
else
{
self.pictureView.hidden = YES;
}
}
- (void)settingFrame
{
self.iconView.frame = self.statuesFrame.iconF;
self.nameView.frame = self.statuesFrame.nameF;
self.vipView.frame = self.statuesFrame.vipF;
self.textView.frame = self.statuesFrame.textF;
if (self.statuesFrame.statuse.picture)
{
self.pictureView.frame = self.statuesFrame.pictureF;
}
}
@end