我想做一个看起来像这样的应用程序。
有很多关于如何使 uitableviewcell 的高度动态化的帖子,所以这对我来说不是问题。我的问题是他们如何将单元格分成具有不同字体的两列?是否有教程或示例如何在 uitableview 中实现?
它看起来像一个带有两个标签的自定义单元格。
以下是基本步骤:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TwoLabelCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel *leftLabel = (UILabel *)[cell viewWithTag:1000];
UILabel *rightLabel = (UILabel *)[cell viewWithTag:1001];
// Set the values based on the indexPath. This is just an example.
leftLabel.text = @"409";
rightLabel.text = @"Vandals and Alans cross the Pyrenees and appear in Hispania.";
}
如果您将与各个行进行大量交互,您可能需要子类化并为每个标签设置属性。(即cell.yearLabel和cell.descriptionLabel)
嗨,您可以通过为自定义 tableviewcell 添加两个标签来获得此信息,请参阅此链接Custom UITableViewCell Using Interface Builder