iphone - 如何更改 UITableViewCellStyleValue2 单元格上标签的大小? (UITableView iPhone)

标签 iphone uitableview

我在应用程序的 UITableView 中使用 UITableViewCellStyleValue2 单元格,并且我希望左列(蓝色文本 - self.textField)比默认值窄得多。我尝试在创建单元格后设置 self.textField.bounds 但这似乎不起作用 - 在调试器中查看似乎尚未设置边界。

我可以通过这种方式编辑默认单元格类型吗?还是应该创建自己的 UITableViewCell 子类?

谢谢。

最佳答案

您可以子类化UITableViewCell并仍然使用UITableViewCellStyleValue2。然后,您可以覆盖layoutSubviews方法来更改标签的大小:

- (void) layoutSubviews {
   [super layoutSubviews]; // layouts the cell as UITableViewCellStyleValue2 would normally look like

   // change frame of one or more labels
   self.textLabel.frame = CGRectMake(...);
   self.detailTextLabel.frame = CGRectMake(...);    
}

关于iphone - 如何更改 UITableViewCellStyleValue2 单元格上标签的大小? (UITableView iPhone),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2093007/

相关文章:

ios - 如何从 soap 加载数组并显示在 TableView 上?

ios - 带有 UITableView Swift 3 的可折叠输入表单

iphone - iOS 应用程序因查询电子邮件按钮而被拒绝

ios - 更改GMSCameraPosition缩放(iOS)

iphone - 为我的 UI 元素设置标签?

ios - UITableView 拖放到表外 = 崩溃

ios - 使用协议(protocol)/委托(delegate)数据传递调用两次的 segue

ios - UITableViewCell 上的自定义 subview 和滚动问题

iphone - 目标没有有效的分布配置文件

ios - 使用 ARC 加载许多 .jpg 文件时收到内存警告和崩溃