Ole*_*leg 5 xcode cocoa-touch ios autolayout ios6
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;
}
Run Code Online (Sandbox Code Playgroud)
如何UILabels
使用自动布局将所有非空垂直居中放置在单元格中?
这是三个标签的外观
如果其中一个UILables
是空的,它看起来如何
这就是我希望它看起来的样子:
这很难实现,但一个简单的捷径可能是使用一个标签,其中包含三行文本,限制为填充单元格的整个高度。然后标签将自动将其内容垂直居中。
您将在单元格上拥有三个字符串属性,而不是三个标签,并且您的设置器将构建最终字符串(用于\n
新行)并设置标签的文本。
如果每行文本都有不同的样式,没问题,因为您可以使用属性字符串。
归档时间: |
|
查看次数: |
3933 次 |
最近记录: |