我有一个分数屏幕,我想在屏幕上垂直显示前 5 个分数(Level1 和 Level2),并用一条线将它们分开。分数来自按降序排序的两个 NSArray 对象。我一直在研究 UITableView/UITableViewCell 以显示多列,它看起来涉及更多我正在寻找的编码。是否有任何其他替代 iOS 控件可以完成这项工作?
有什么想法吗?
这就是它的样子
Level1 Level2 ====== ====== 34 46 32 33 24 28 20 21 16 18
最佳答案
你有两个选择:
这里最优雅的解决方案(尽管你不情愿)是子类化 UITableViewCell
并提供你自己的表格单元格实现,每个单元格都有两个 UILabel
列值,然后您可以在单元格中间画一条垂直线(一旦显示所有单元格,它就会变成表格 View 中间的一条线)。
另一种选择是简单地向 -tableView:cellForRowAtIndexPath:
中的 TableView 单元格添加一个额外的 UILabel
并设置 frame
以便它位于单元格的右侧:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
self.textLabel.text = [firstArray objectAtIndex:indexPath.row];
UILabel *secondColumnLabel = [[UILabel alloc] initWithFrame:CGRectMake(<customize your values here>];
secondColumnLabel.backgroundColor = [UIColor clearColor];
// any other customization goes here
secondColumnLabel.text = [secondArray objectAtIndex:indexPath.row];
[cell addSubview:secondColumnLabel];
}
关于ios - 如何将分数垂直显示为 2 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14328880/