如何在iPhone iOS4中将UITableViewCellStyleSubtitle textAlignment设置为居中? [英] How to set UITableViewCellStyleSubtitle textAlignment to center in iPhone iOS4?

查看:307
本文介绍了如何在iPhone iOS4中将UITableViewCellStyleSubtitle textAlignment设置为居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从使用iPhone SDK 4将XCode升级到版本3.2.3后,我的代码不再有效了。

Since upgraded XCode to Version 3.2.3 with iPhone SDK 4 my code doesn't work anymore.

我有一个样式 UITableViewCellStyleSubtitle 并且想要设置 textAlign textLabel detailTextLabel center ,但没有任何反应。
之前使用的相同代码现在不再工作了。在 UITableViewCellStyleDefault 中心对齐仍然有效。

I have a default cell with style UITableViewCellStyleSubtitle and want to set the textAlignment of textLabel and detailTextLabel to center, but nothing happens. Same code used before now not working anymore. On UITableViewCellStyleDefault center alignment still works.

有谁知道如何解决这个问题?我实际上不想使用自定义单元格。

Does anyone know how to solve this? I don't want to use a custom cell only in fact of this.

推荐答案

文本不居中的原因是因为标签只与文字一样宽。您可以通过设置文本标签的背景颜色来确认:

The reason why text isn't centered is because the label is only as wide as the text. You can confirm this by setting the background color of the text label:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.textLabel.backgroundColor = [UIColor orangeColor];
}

手动设置单元格宽度似乎也没有效果。因此,您应该添加自己的子视图或创建自己的 UITableViewCell 的子类。

Setting the cell width manually also doesn't seem to have an effect. So you should really add your own subviews or create your own subclass of UITableViewCell.

<$ c的文档$ c> UITableViewCellStyleSubtitle 甚至说:


具有左对齐<的单元格的样式/ strong>
标签位于顶部,另一个
左对齐标签位于较小的
灰色文本中。 iPod应用程序使用这种风格的
单元格。

A style for a cell with a left-aligned label across the top and a left-aligned label below it in smaller gray text. The iPod application uses cells in this style.

这篇关于如何在iPhone iOS4中将UITableViewCellStyleSubtitle textAlignment设置为居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆