代码之家  ›  专栏  ›  技术社区  ›  Knodel

如何对齐UITableView的文本?

  •  0
  • Knodel  · 技术社区  · 16 年前

    在我的应用程序中,我有一个UITableView,我想把文本的对齐方式改为居中(不仅仅是像这样从侧面)

         cell.textAlignment = UITextAlignmentCenter;
    

    你能帮助我吗?

    2 回复  |  直到 16 年前
        1
  •  2
  •   Henrik N    16 年前

    你能澄清一下这个问题吗?如果你使用 UITableViewCellStyleDefault 增加细胞高度

    - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      return 100;
    }
    

    然后标签将垂直居中,而无需您的任何努力。

    也, cell.textAlignment = … 不赞成赞成 cell.textLabel.textAlignment = …

        2
  •  1
  •   Sonny Saluja    15 年前

    这就可以了,假设你正在使用文本标签为你的文本。

    cell.textLabel.textAlignment=UITextAlignmentCenter