cell.h文件如下
//// ListCell.h// Wealthy Chat//// Created by cafuc on 16/4/10.// Copyright © 2016年 cafuc. All rights reserved.//#import#import "CellData.h"@interface ListCell : UITableViewCell{ //cell中具有的属性 //头像 UIImageView *imageViewHead; //昵称 UILabel *labelNickName; //日期 UILabel *labelDate; //年龄 UILabel *labelAge; //收入 UILabel *labelIncome; //签名 UILabel *labelSign; //背景图 UIImageView *imageViewBackgroundImage; }-(void)initCellData:(CellData *)bean;@end
cell.m文件如下
//// ListCell.m// Wealthy Chat//// Created by cafuc on 16/4/10.// Copyright © 2016年 cafuc. All rights reserved.//#import "ListCell.h"#import "UIImageView+AFNetworking.h"#import "Utils.h"@implementation ListCell-(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { NSLog(@"cell存在"); //设置cell背景色 self.backgroundColor = [UIColor blackColor]; //定义cell上的各个控件 //假设图片为48*48 x:10 y:10 imageViewHead = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 48, 48)]; imageViewHead.layer.masksToBounds = YES; imageViewHead.layer.cornerRadius = 24; //imageViewHead.contentMode = UIViewContentModeScaleAspectFit; imageViewHead.image = [UIImage imageNamed:@"default"]; [self.contentView addSubview:imageViewHead]; //昵称 x:10+48+10 y:15 labelNickName = [[UILabel alloc] initWithFrame:CGRectMake(68, 15, 100, 20)]; labelNickName.text = @"--"; labelNickName.font = [UIFont fontWithName:@"Arial" size:15]; labelNickName.textColor = [UIColor whiteColor]; [self.contentView addSubview:labelNickName]; //性别 x:20+60+20 y:110 //labelGender = [[UILabel alloc] initWithFrame:CGRectMake(200, 100+15, 30, 20)]; //labelGender.text = @"--"; //[self.contentView addSubview:labelGender]; //年龄 x:20+130 y:110 labelAge = [[UILabel alloc] initWithFrame:CGRectMake(250, 100+15, 30, 20)]; labelAge.text = @"--"; [self.contentView addSubview:labelAge]; } return self;}-(void)initCellData:(CellData *)bean{ [imageViewHead setImageWithURL:[NSURL URLWithString:bean.viewHead] placeholderImage:[UIImage imageNamed:@"default"]]; labelNickName.text = bean.nickName; labelAge.text = bean.age;}@end