如何在适合的单元格中显示自定义大小的图像

时间:2010-07-03 08:13:33

标签: iphone objective-c cocoa-touch

我在表格单元格右侧的iphone应用程序图像是从xml提取中提取的。知道我想以固定大小显示它们可以任何身体帮助我。         下面是代码

  int blogEntryIndex1 = [indexPath indexAtPosition: [indexPath length] -1];
  imgstring=[[blogEntries objectAtIndex: blogEntryIndex1] objectForKey: @"image"];
    NSURL *url = [NSURL URLWithString:imgstring];
      NSData *data = [NSData dataWithContentsOfURL:url];
      UIImage *img = [[UIImage alloc] initWithData:data];
            cell.imageView.image=img;
      cell.textLabel.text=headline;

在此先感谢我将等待

1 个答案:

答案 0 :(得分:1)

如果您的图像不需要任何缩放,请将UIImageView的内容模式设置为UIViewContentModeScaleAspectFit或UIViewContentModeCenter。

[yourImageView setContentMode:UIViewContentModeScaleAspectFit];

查看API中的示例。有一种更好的方法来加载表格视图单元格的图像。 http://developer.apple.com/iphone/library/samplecode/LazyTableImages

为了更好地理解表视图细胞的解剖结构,请阅读: http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html

相关问题