我有一个UITableViewCell包含两个UILabels 的自定义。一个用于Title,另一个用于Abstract。摘要是从 Web 服务返回的,它至少有 10 行长。我想在UILabel.
我已将抽象UILabel noOfLines设置为 0。换行符设置为wordwrapping。我什至在分配抽象文本后调用sizeToFit,如下所示:
-(void) configure:(Story *)story
{
self.titleLabel.text = story.title;
self.abstractLabel.text = story.abstract;
[self.abstractLabel sizeToFit];
}
如下图UITableView cellForRowIndex所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"StoryCell";
StoryCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Story *story = [_stories objectAtIndex:[indexPath row]];
[cell configure:story];
return cell;
}
结果如下所示:
