Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table view cell's label won't center align unless number of lines is 1

I have a UITableViewCell subclass alone in a xib. The cell has a UILabel subview in it. The text alignment in IB is set to center, but unless numberOfLines is set to 1, the label snaps over to left alignment (even though the "Alignment" in IB is set to center sill). I tried setting the textAlignment to NSTextAlignmentCenter in the cell's awakeFromNib, and also in the corresponding table view's cellForRowAtIndexPath:, but still no luck, even though when I check the cell's textAlignment value at various breakpoints it's NSTextAlignmentCenter.

How can I center align multiple lines of text in a UILabel?

like image 364
Marty Avatar asked Dec 02 '25 09:12

Marty


1 Answers

Of course, right after I post the question, I figure it out.

If the "Autoshrink" has "Tighten Letter Spacing" selected in IB, it snaps it to the left alignment. Uncheck this to have it stay centered.

like image 181
Marty Avatar answered Dec 03 '25 23:12

Marty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!