我的自定义UILabels中有三个UITableViewCell。可能是某些UILabels将为空(label.text == @"")
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"EventCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *key = [[keysArray objectAtIndex:indexPath.section] description];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
namelabel.text = @"Label 1";
UILabel *locationLabel = (UILabel *)[cell viewWithTag:101];
location.text = @"Label 2";
UILabel *timeLabel = (UILabel *)[cell viewWithTag:102];
timeLabel.text = @"";
return cell;
}如何使用自动布局将所有非空UILabels垂直地集中在单元格中?
这是三个标签的样子

当UILables 中的一个为空时,它的外观如何?

--这就是我希望它看起来的样子:

发布于 2013-02-10 09:26:37
这是很难实现的,但是一个简单的快捷方式可能是用一个标签代替,用三行文本来填充整个单元格的高度。标签将自动对其内容垂直。
您将在单元格上有三个字符串属性,而不是三个标签,您的设置程序将构建最后一个字符串(新行使用\n )并设置标签文本。
如果每一行文本都有不同的样式,没有问题,因为您可以使用属性化字符串。
https://stackoverflow.com/questions/14791831
复制相似问题