【问题标题】:iPhone: image in table cell - wrong position & not scaled correctly in iPhone 3.0iPhone:表格单元格中的图像 - 位置错误且在 iPhone 3.0 中未正确缩放
【发布时间】:2011-02-12 21:39:21
【问题描述】:

我在 iPhone 3.x 应用程序中有一个自定义表格单元格来显示篮球运动员数据,包括一张图片。这是我的表控制器代码:

UIImageView *theImage = (UIImageView *) [cell viewWithTag:0];

theImage.image = [manager getSmallImageForPlayer: data.number];         
theImage.frame = CGRectMake(14, 0, 30, 44);
theImage.clipsToBounds = YES;
theImage.contentMode = UIViewContentModeScaleAspectFit;
theImage.autoresizingMask = UIViewAutoresizingFlexibleHeight && UIViewAutoresizingFlexibleWidth;
theImage.autoresizesSubviews = YES;

这是它在 iPhone SDK 3.0 模拟器中的样子:

3.0 simulator screenshot http://img96.imageshack.us/img96/9550/imageintablecell30.png

这是它在 iPhone SDK 3.1.3 模拟器中的样子:

3.1.3 simulator screenshot http://img185.imageshack.us/img185/9269/imageintablecell313.png

所以我有两个问题:

  1. 在这两个版本中,图像视图从表格单元格中的位置 (0,0) 开始,即使我将框架设置为从 (14,0) 开始。
  2. 在 3.0 模拟器(和 3.0 设备)中,图像没有正确缩小,即使我将图像视图内容模式设置为“UIViewContentModeScaleAspectFit”。但相同的代码在 3.1.3 模拟器/设备中运行良好。

谁能帮我解决这两个问题?

【问题讨论】:

  • 如何将UIImageView 添加到UITableViewCell
  • 我没有,它已经在自定义表格单元格 MIB 中,我使用“viewWithTag”从中读取它,然后设置它的属性。

标签: iphone iphone-sdk-3.0 uitableview uiimageview


【解决方案1】:

我在Apple forums 上找到了答案:使用“0”作为图像视图的标签号搞砸了;只需将其更改为“5”即可解决两个问题(图像未缩放、位置错误)。

【讨论】:

    【解决方案2】:

    您可以尝试创建自己的 UIImageView 并将其作为子视图添加到表格单元格

    【讨论】:

      猜你喜欢
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-23
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-30
      相关资源
      最近更新 更多