TextAlignment not working for UITableViewCell Label

1.3k views Asked by At

I am trying to center the textLabel in my UITableViewCell with this code:

 cell.textLabel.textAlignment = NSTextAlignmentCenter;

However nothing is changing and the label is still in the left side. Anyone know why?

1

There are 1 answers

2
Mick MacCallum On BEST ANSWER

You're using either the subtitle or right detail UITableViewCell style aren't you? I these are the two styles that for what ever reason don't allow you to override the text label's alignment.

To solve this problem, you can make a simple subclass of UITableViewCell with two labels in the same position as they are in the table cell style that you wish to emulate. In fact, to achieve this, the only two lines of code you'd need to write would be the properties for the labels. Then you could do the rest of the work on a prototype cell in Interface Builder.