iphone - 如何在 iPhone iOS 4 中设置 UITableViewCell 样式副标题文本对齐方式居中?

标签 iphone uitableview ios4

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

我有一个样式为 UITableViewCellStyleSubtitle 的默认单元格,并且希望将 textLabeldetailTextLabeltextAlignment 设置为center,但什么也没发生。 之前使用的相同代码现在不再工作。在 UITableViewCellStyleDefault 上居中对齐仍然有效。

有谁知道怎么解决这个问题吗?事实上我不想仅使用自定义单元格。

最佳答案

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

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

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

UITableViewCellStyleSubtitle 的文档甚至说:

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 - 如何在 iPhone iOS 4 中设置 UITableViewCell 样式副标题文本对齐方式居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3100447/

相关文章:

iphone - 从 plist 到 UIPickerView

iphone - 如何让 Qemu USB Passthrough 为 iPad/iPhone 工作?

iphone - phonegap 中#import "PhoneGapDelegate.h"错误消息?

ios - 如何获取 UITableView 中每个动态创建的单元格的文本字段值

ios - 通过 Storyboard有效地传递 NSManagedObject

ios - UITableView 正在添加空行并禁用滚动

ios - UIView 中需要 uitableview 分组背景吗?

iphone - 如何在 CGAffineTransform 中传递值 Make

iOS UITableView 意外添加边距

iphone - 如何为 NSLog( @"mytext") 打字和光标焦点设置预定义宏键,并选择在 "mytext "之间进行编辑