UITableViewCell 的各种样式代码

样式 一:

UITableViewCell <wbr>的各种样式代码

- (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;

}

 

 

 

 

样式二:

UITableViewCell <wbr>的各种样式代码
 

- (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;

 

}

 

 

 

 

 

样式 三:

UITableViewCell <wbr>的各种样式代码
 

 

- (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;

 

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值