开发者

Objective C: Cell.ImageView.image size Inconsistent

开发者 https://www.devze.com 2023-03-19 17:09 出处:网络
I have a tableview which displays an image that is obtained from a server (via URL) [cell.imageView setImageWithURL:[NSURL URLWithString:avatar_url]

I have a tableview which displays an image that is obtained from a server (via URL)

[cell.imageView setImageWithURL:[NSURL URLWithString:avatar_url] 
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

However, I am开发者_如何学C faced with the problem of inconsistent sizing of the image displayed in my cell. (see screenshots below):

Objective C: Cell.ImageView.image size Inconsistent

Objective C: Cell.ImageView.image size Inconsistent

1) How can I fix the size of the images retrieved?

2) How can I fix the cell.imageView's frame's size? Doing the following does not seem to work (cell.imageView.frame = CGRectMake(5,5,32,32).


You need to set the contentMode of the cell's Imageview

like this,

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

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

精彩评论

暂无评论...
验证码 换一张
取 消