Objective C:Cell.ImageView.image大小不一致

时间:2011-07-13 06:01:36

标签: objective-c ios uiimageview

我有一个tableview,显示从服务器(通过URL)

获取的图像
[cell.imageView setImageWithURL:[NSURL URLWithString:avatar_url] 
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

但是,我遇到了单元格中显示的图像大小不一致的问题。 (见下面的截图):

enter image description here

enter image description here

1)如何修复检索图像的大小?

2)如何修复cell.imageView的框架大小?执行以下操作似乎不起作用(cell.imageView.frame = CGRectMake(5,5,32,32)。

1 个答案:

答案 0 :(得分:5)

您需要设置单元格Imageview的contentMode

像这样,

cell.imageView.contentMode = /*(something from the below list)*/;

typedef enum {
   UIViewContentModeScaleToFill,
   UIViewContentModeScaleAspectFit,
   UIViewContentModeScaleAspectFill,
   UIViewContentModeRedraw,
   UIViewContentModeCenter,
   UIViewContentModeTop,
   UIViewContentModeBottom,
   UIViewContentModeLeft,
   UIViewContentModeRight,
   UIViewContentModeTopLeft,
   UIViewContentModeTopRight,
   UIViewContentModeBottomLeft,
   UIViewContentModeBottomRight,
} UIViewContentMode;