【发布时间】:2013-08-09 01:51:51
【问题描述】:
通过this question 我了解到,为了通过 NSTextAlignmentCenter 在 UILabel 中居中对齐文本,我必须禁用“字母缩紧间距”和this guy agrees。
他们提到在界面生成器中禁用此选项,但是,据我所知,我的 uilabel 在 IB 中无法访问。这是因为我正在尝试更改 uitableview 中单元格的“textLabel”。我继续尝试尝试在代码中禁用某些东西:
cell.textLabel.numberOfLines = 1;
cell.textLabel.adjustsFontSizeToFitWidth = NO;
cell.textLabel.adjustsLetterSpacingToFitWidth = NO;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = @"My Centered Text";
但是,这些似乎都没有任何效果。文本仍然左对齐。
【问题讨论】:
-
cell.textLabel.textAlignment = NSTextAlignmentCenter;应该是你所需要的。前3行都是默认值,不需要设置。
标签: ios uitableview