【发布时间】:2013-01-25 08:32:26
【问题描述】:
我的自定义UITableViewCell 中有三个UILabels。
可能有些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 之一为空时的外观
这就是我想要的样子:
【问题讨论】:
-
您是在代码中还是在界面构建器中构建单元格?标签是否为空有什么关系?
-
在 IB 中。我希望我的标签在容器中居中。制作起来并不难,但是当其中一个标签为空时,我会在其他两个标签之间出现一个看起来不太好的间隙
-
这可能很难,因为一个空的 UILabel 可能不会声明宽度,但肯定是高度,所以你可能需要沿着 'of one label is empty, remove那个标签'。
-
好吧,我可以调用 -removeFromSuperview 或将空标签设为 nil。我该怎么做?我应该使用哪些约束来对齐其他标签?
标签: ios xcode cocoa-touch ios6 autolayout