使用UITableViewCellStyleSubtitle在UITableViewCell中重叠

时间:2009-09-08 21:12:35

标签: uitableview

我正在使用带有字幕的表格单元格,并希望我的文字变得更大。改变大小

cell.textLabel.font = [UIFont boldSystemFontOfSize:30];

和单元格高度heightForRowAtIndexPath80我遇到textLabeldetailTextLabel隐藏一半的问题。我很惊讶这是处理得不好。我试图改变标签的边界,但没有效果。如何设置“位置”,“内容矩形”或任何有大textLabel和小detailTextLabel的内容?

1 个答案:

答案 0 :(得分:1)

我相信这在iOS的更高版本中已得到修复。但是,如果您确实要为“字幕”或其他样式单元格提供自定义布局(为了利用某些布局功能,例如定位图像/附件等),您可以通过对它们进行子类化来轻松完成。在子类init中,使用所需样式的超类并覆盖layoutSubviews,如下所示:

- (void)layoutSubviews
{
    [super layoutSubviews];
    // Set the content view frame
    CGRect cvFrame = self.contentView.frame;
    cvFrame.origin.y = 0;
    cvFrame.size.height = 80;
    self.contentView.frame = cvFrame;
    // Set the text label position
    CGRect tlFrame = self.textLabel.frame;
    tlFrame.origin.y = 2;
    self.textLabel.frame = tlFrame;
    // Set the detail label position
    CGRect dtlFrame = self.detailTextLabel.frame;
    dtlFrame.origin.y = 2 + tlFrame.size.height + 2;
    self.detailTextLabel.frame = dtlFrame;
}

这样您就可以使用[super layoutSubviews]中设置的帧值并设置自己的帧值。如果要向单元格添加更多视图,也可以在此处设置其位置。