cell.h文件以下code
// // ListCell.h // Wealthy Chat // // Created by cafuc on 16/4/10. // Copyright © 2016年 cafuc. All rights reserved. // #import <UIKit/UIKit.h> #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