如何增加 UITableViewCell 中标题和副标题之间的空间?

子类 UITableViewCell 以创建自定义单元格。这是一个很好的方法来做到这一点。这很简单,并且还可以让您在未来使您的细胞看起来像您想要的那样。另一个好处是每个单元格都是通用的,因此您只需创建一个自定义类。
您可以在单元格内容视图中添加两个标签,而不是设置单元格标签。根据需要调整 y 原点。添加 heightForRowAtIndexPath 将增加您的单元格高度。
如果您的行高更大,则标题和副标题将垂直居中对齐。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
最好的方法是继承 UITableViewCell。这样,您就可以完全控制标签的位置。如果这不是一个选项,您可以手动修改每个标签的框架。
UITableViewCell)。
更新您的表格视图类。
在 .中使用您的自定义单元格的标识符cellForRowAtIndexPath。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = YOUR CUSTOM CELL's IDENTIFIER;
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//configure your cell.
cell.YOURLABEL1.text=@"YOUR TEXT FOR LABEL 1";
cell.YOURLABEL2.text=@"YOUR TEXT FOR LABEL 2"
return cell;
}
而已。