ios - 如何将分数垂直显示为 2 列

标签 ios objective-c xcode

我有一个分数屏幕,我想在屏幕上垂直显示前 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/

相关文章:

ios - CoreData iOS App的Sqlite文件位置的位置

ios - UiTextView 文本来分隔 UITextField 的

ios - TableView 图像仅在向下滚动时显示

swift - 按下键盘后面的按钮时应用程序崩溃

ios - 更改个人 Apple 开发者帐户的所有权

ios - 在 UIView 后面捕获(动画)屏幕

ios - LAPACK sgelss 用法

iphone - Objective C用字符串动态调用方法

objective-c - NSButton setEnabled 不起作用

Xcode 3.2.3 - 无 SDK 3.1.3