样式 一:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
UILabel *firRowLabel = [[UILabel alloc] init];
firRowLabel.tag = 11;
firRowLabel.frame = CGRectMake(10, 5, ScreenWidth - 20,20);
[self.contentView addSubview:firRowLabel];
firRowLabel.textAlignment = NSTextAlignmentLeft;
firRowLabel.textColor = [UIColor blackColor];
firRowLabel.font = [UIFont systemFontOfSize:17];
UIImageView *secRowIcon = [[UIImageView alloc] init];
secRowIcon.tag = 21;
secRowIcon.frame = CGRectMake(10, CGRectGetMaxY(firRowLabel.frame)+5+5, 10, 10);
[self.contentView addSubview:secRowIcon];
secRowIcon.image = [UIImage imageNamed:@"list_user"];
UILabel *secRowLabel = [[UILabel alloc] init];
secRowLabel.tag = 22;
secRowLabel.frame = CGRectMake(CGRectGetMaxX(secRowIcon.frame)+5,CGRectGetMaxY(firRowLabel.frame)+5, ScreenWidth - 20-15,20);
[self.contentView addSubview:secRowLabel];
secRowLabel.textAlignment = NSTextAlignmentLeft;
secRowLabel.textColor = [UIColor lightGrayColor];
secRowLabel.font = [UIFont systemFontOfSize:15];
UIImageView *thiRowIcon = [[UIImageView alloc] init];
thiRowIcon.tag = 31;
thiRowIcon.frame = CGRectMake(10, CGRectGetMaxY(secRowLabel.frame)+5+5, 10, 10);
[self.contentView addSubview:thiRowIcon];
thiRowIcon.image = [UIImage imageNamed:@"list_pin"];
UILabel *thiRowLabel = [[UILabel alloc] init];
thiRowLabel.tag = 32;
thiRowLabel.frame = CGRectMake(CGRectGetMaxX(secRowIcon.frame)+5,CGRectGetMaxY(secRowLabel.frame)+5, ScreenWidth - 20-15,20);
[self.contentView addSubview:thiRowLabel];
thiRowLabel.textAlignment = NSTextAlignmentLeft;
thiRowLabel.textColor = [UIColor lightGrayColor];
thiRowLabel.font = [UIFont systemFontOfSize:15];
}
return self;
}
样式二:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//cell高为60
CGFloat cellW = self.bounds.size.width;
//图片
UIImageView *icon = [[UIImageView alloc] init];
icon.tag = 100;
icon.frame = CGRectMake(10,5, 50, 50);
[self.contentView addSubview:icon];
icon.layer.cornerRadius = 25;
icon.layer.masksToBounds = YES;
UILabel *firRowLabel = [[UILabel alloc] init];
firRowLabel.tag = 11;
firRowLabel.frame = CGRectMake(CGRectGetMaxX(icon.frame)+10, 5,70,25);
[self.contentView addSubview:firRowLabel];
firRowLabel.textAlignment = NSTextAlignmentLeft;
firRowLabel.textColor = [UIColor blackColor];
firRowLabel.font = [UIFont systemFontOfSize:17];
UILabel *firRowSecLabel = [[UILabel alloc] init];
firRowSecLabel.tag = 12;
firRowSecLabel.frame = CGRectMake(CGRectGetMaxX(firRowLabel.frame)+10, 5, cellW - 20-CGRectGetMaxX(firRowLabel.frame),25);
[self.contentView addSubview:firRowSecLabel];
firRowSecLabel.textAlignment = NSTextAlignmentLeft;
firRowSecLabel.textColor = [UIColor lightGrayColor];
firRowSecLabel.font = [UIFont systemFontOfSize:15];
UILabel *SecRowLabel = [[UILabel alloc] init];
SecRowLabel.tag = 21;
SecRowLabel.frame = CGRectMake(CGRectGetMaxX(icon.frame)+10,CGRectGetMaxY(firRowLabel.frame)+5,cellW - CGRectGetMaxX(icon.frame)-20,20);
[self.contentView addSubview:SecRowLabel];
SecRowLabel.textAlignment = NSTextAlignmentLeft;
SecRowLabel.textColor = [UIColor lightGrayColor];
SecRowLabel.font = [UIFont systemFontOfSize:15];
}
return self;
}
样式 三:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//cell的高度为80
UIImageView *firRowIcon = [[UIImageView alloc] init];
firRowIcon.tag = 11;
firRowIcon.frame = CGRectMake(10,5+5, 10, 10);
[self.contentView addSubview:firRowIcon];
firRowIcon.image = [UIImage imageNamed:@"list_time"];
UILabel *firRowLabel = [[UILabel alloc] init];
firRowLabel.tag = 12;
firRowLabel.frame = CGRectMake(CGRectGetMaxX(firRowIcon.frame)+5,5, ScreenWidth - 20-15,20);
[self.contentView addSubview:firRowLabel];
firRowLabel.textAlignment = NSTextAlignmentLeft;
firRowLabel.textColor = [UIColor blackColor];
firRowLabel.font = [UIFont systemFontOfSize:17];
UIImageView *secRowIcon = [[UIImageView alloc] init];
secRowIcon.tag = 21;
secRowIcon.frame = CGRectMake(10, CGRectGetMaxY(firRowLabel.frame)+5+5, 10, 10);
[self.contentView addSubview:secRowIcon];
secRowIcon.image = [UIImage imageNamed:@"list_user"];
UILabel *secRowLabel = [[UILabel alloc] init];
secRowLabel.tag = 22;
secRowLabel.frame = CGRectMake(CGRectGetMaxX(secRowIcon.frame)+5,CGRectGetMaxY(firRowLabel.frame)+5, ScreenWidth - 20-15,20);
[self.contentView addSubview:secRowLabel];
secRowLabel.textAlignment = NSTextAlignmentLeft;
secRowLabel.textColor = [UIColor lightGrayColor];
secRowLabel.font = [UIFont systemFontOfSize:15];
UIImageView *thiRowIcon = [[UIImageView alloc] init];
thiRowIcon.tag = 31;
thiRowIcon.frame = CGRectMake(10, CGRectGetMaxY(secRowLabel.frame)+5+5, 10, 10);
[self.contentView addSubview:thiRowIcon];
thiRowIcon.image = [UIImage imageNamed:@"list_pin"];
UILabel *thiRowLabel = [[UILabel alloc] init];
thiRowLabel.tag = 32;
thiRowLabel.frame = CGRectMake(CGRectGetMaxX(secRowIcon.frame)+5,CGRectGetMaxY(secRowLabel.frame)+5, ScreenWidth - 20-15,20);
[self.contentView addSubview:thiRowLabel];
thiRowLabel.textAlignment = NSTextAlignmentLeft;
thiRowLabel.textColor = [UIColor lightGrayColor];
thiRowLabel.font = [UIFont systemFontOfSize:15];
}
return self;
}