How to align a UITableView's text?
In my app I have a UITableView and I want to change the text's alignme开发者_运维百科nt to center (not only from the sides like this
cell.textAlignment = UITextAlignmentCenter;
but from up and down, as well).
Can you help me? thanks in advance!
Could you please clarify the question? If you use UITableViewCellStyleDefault
and increase cell height something like
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
then the label will be vertically centered without any effort on your part.
Also, cell.textAlignment = …
is deprecated in favor of cell.textLabel.textAlignment = …
.
This will do it, assuming you are using textLabel for your text.
cell.textLabel.textAlignment = UITextAlignmentCenter
精彩评论