【问题标题】:Change the width of the cell content更改单元格内容的宽度
【发布时间】:2010-05-16 17:14:05
【问题描述】:

我想改变单元格内容的宽度。 (见图片) alt text http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/Art/tv_cell_parts.jpg

我的代码:

 CGSize contentViewSize = cell.contentView.bounds.size;
    contentViewSize.width = 20.0f;

但是没有效果,怎么回事?
任何建议将不胜感激,谢谢。

【问题讨论】:

  • 嗨,也许布局是由 tableView 完成的,并且覆盖了您的设置。如果您在设置宽度后 NSLog 退出宽度,它会显示 20.0 吗?如果我需要任何不是很接近标准的东西,我通常会为单元格制作自己的 UIView。
  • 是的,它说 20.0。感谢您对 UIView 的建议。

标签: iphone objective-c


【解决方案1】:

您需要为单元格的contentView 重新分配frame

CGRect oldFrame = cell.contentView.frame;
cell.contentView.frame = CGRectMake( oldFrame.origin.x,
                                     oldFrame.origin.y, 
                                     oldFrame.size.width + 20, 
                                     oldFrame.size.height );

【讨论】:

  • 它不起作用。其实我想改变textLabel和detailTextLabel的宽度,所以我也尝试设置宽度 "CGSize contentViewSize = cell.contentView.bounds.size; contentViewSize.width = 20.0f;" 。也不行……不过还是谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多