Centering Text In UITableViewCell (iPhone SDK)
Unfortunately the iPhone SDK 2.2 has a bug that prevents centering UITableViewCell text using:
cell.textAlignment = UITextAlignmentCenter;
Here is a work-around:
UILabel* label = [[[cell contentView] subviews] objectAtIndex:0];
label.textAlignment = UITextAlignmentCenter;
label.textAlignment = UITextAlignmentCenter;












4 comments:
Was poking around the net and found this page. The update for folks who may come across it is to set textAlignment on the property of the label of the UITableViewCell, or in other code words:
UITableViewCell *cell; //abbreviated for comment
cell.textLabel.textAlignment = UITextAlignmentCenter;
Cheers!
Thanks a lot for this tip Tyler! It works great!
Hm, this doesn't work in 4.3. There are some properties that inexplicably can't be set when you return the cell, but instead must be set in the delegate's willDisplayCell method.
Thanks a lot, it worked for me
Post a Comment