2

Through this question I've learned that in order to center align text in UILabel via NSTextAlignmentCenter I must disable "letter tighten spacing" and this guy agrees.

They mention disabling this option in interface builder, however, my uilabel isn't accessible in IB as far as I know. This is because I am trying to change the "textLabel" of a cell in a uitableview. I proceeded to attempt to try disabling things in code:

cell.textLabel.numberOfLines = 1;
cell.textLabel.adjustsFontSizeToFitWidth      = NO;
cell.textLabel.adjustsLetterSpacingToFitWidth = NO;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = @"My Centered Text";

However, none of these seem to have any effect. The text is still left aligned.

Community
  • 1
  • 1
dtmland
  • 2,136
  • 4
  • 22
  • 45
  • cell.textLabel.textAlignment = NSTextAlignmentCenter; should be all you need. The first 3 lines are all the default values, so no need to set them. – rdelmar Aug 09 '13 at 01:58

1 Answers1

8

Found the problem! Had to change the cell style to UITableViewCellStyleDefault:

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
Community
  • 1
  • 1
dtmland
  • 2,136
  • 4
  • 22
  • 45