自动布局UILabels [英] Auto Layout UILabels
问题描述
我在自定义 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
使用自动布局在单元格中垂直?
b 看起来如何>> 这是我想要的外观: 这是很难实现的,但是一个简单的快捷方式可能是有一个单一的标签,三行文字,约束填充整个单元格的高度。然后标签将垂直自动居中其内容。 您将在单元格上有三个字符串属性,而不是三个标签,并且您的setter将构建最终字符串(使用 如果每行文字都有不同的样式,没有问题,因为您可以使用属性字符串。 I have three How can I centre all non-empty This is how it looks with three labels How it looks when one of And this is how I want it to look: This is tricky to achieve, but a simple shortcut may be to have a single label instead, with three lines of text, constrained to fill the whole height of the cell. The label will then auto-center its contents vertically. You'd have three string properties on the cell instead of three labels, and your setters would build the final string (using If each line of text has different styling, no problem, as you can use attributed strings. 这篇关于自动布局UILabels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b
UILables
之一为空时如何查看
\\\
为新行)并设置标签的文本。
UILabels
in my custom UITableViewCell
.
It might be that some UILabels
will be empty (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
vertically in the cell using auto-layout?UILables
is empty\n
for new lines) and set the label's text.