美文网首页
cell 代码块

cell 代码块

作者: 全世界妳最美 | 来源:发表于2018-08-06 11:09 被阅读11次

1.cell中的布局

//
//  RiBaoTableViewCell.m
//  YDLQ
//
//  Created by apple on 2018/1/16.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "RiBaoTableViewCell.h"


@implementation RiBaoTableViewCell

+(instancetype)Ribaotableviewcell:(UITableView *)tableView{
    
    NSString *cellID = @"RiBaoTableViewCell";
    RiBaoTableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[RiBaoTableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:cellID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//
    cell.layer.cornerRadius = 4;// 圆角
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setV];
  
    }
    return self;
}
- (void)setV{
    NSArray *arr = @[@"日期:",@"公司名称:",@"工作区域:"];
    UILabel *lastLab;
    for (int i= 0; i < arr.count; i++) {
        UILabel *lab = [[UILabel alloc] init];
        [self.contentView addSubview:lab];
        lab.text = arr[i];
        lab.font = WJFontSize(14);
        UILabel *lab2 = [[UILabel  alloc] init];
        [self.contentView addSubview:lab2];
        lab2.tag = 10000+i;
        lab2.textColor = QkColorText;
        lab2.font = WJFontSize(14);
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            if (lastLab) {
                make.top.mas_equalTo(lastLab.mas_bottom).offset(10);
            }else{
                make.top.mas_equalTo(self.contentView).offset(10);
            }
            make.size.mas_equalTo(CGSizeMake(100, 20));
            make.left.mas_equalTo(self.contentView).offset(10);
        }];
        lastLab = lab;
        [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(lab.mas_right).offset(10);
            make.centerY.equalTo(lab);
            make.right.mas_lessThanOrEqualTo(self.contentView).offset(10);
            make.height.mas_equalTo(lab);
        }];

    }
}
- (void)setModel:(RIbaoModel *)model{
    _model = model;
    UILabel *lab1 = [self.contentView viewWithTag:10000];
    UILabel *lab2 = [self.contentView viewWithTag:10001];
    UILabel *lab3 = [self.contentView viewWithTag:10002];
    lab1.text = [NSString isNullToString:_model.rq];
    lab2.text = [NSString isNullToString:_model.companyname];
    lab3.text = [NSString isNullToString:_model.gzqy];
}

@end

2.UIViewController 在调用的时候

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RiBaoTableViewCell *cell = [RiBaoTableViewCell Ribaotableviewcell:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.arrData[indexPath.row];
    return cell; 
}

相关文章

网友评论

      本文标题:cell 代码块

      本文链接:https://www.haomeiwen.com/subject/siewvftx.html