Step1: 新建一个类CTXibCell继承自UITableViewCell

Step2: 新建一个空白xib,名字与要关联的CTXibCell一致


Step3: 在xib界面,点击右上角的+号,并搜索找到UITableViewCell控件拖动到xib界面上

将xib与目标视图关联

可拖动四周及角落改变大小以便于布局

Step4: 设置控件属性

比如设置文字颜色,可在Color列表中拉到最底部选择Custom设置自定义的十六进制颜色

Step5: 设置约束







Step6: 使用
方式一:
static NSString *iden = @"CTXibCellID";
CTXibCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"CTXibCell" owner:nil options:nil] lastObject];
}
return cell;
方式二:
先注册cell
[self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([CTXibCell class]) bundle:nil] forCellReuseIdentifier:@"CTXibCellID"];
static NSString *iden = @"CTXibCellID";
CTXibCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
return cell;
网友评论