Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C: Cell.ImageView.image size Inconsistent

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 faced with the problem of inconsistent sizing of the image displayed in my cell. (see screenshots below):

enter image description here

enter image description here

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).

like image 408
Zhen Avatar asked Apr 24 '26 13:04

Zhen


1 Answers

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;
like image 98
Robin Avatar answered Apr 26 '26 02:04

Robin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!