开发者

How to align a UITableView's text?

开发者 https://www.devze.com 2023-01-02 05:55 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消