swift - Incorrect UITableViewCell height UIImageView -


i have uitableviewcell contains uiimageview. using uitableviewautomaticdimension working other cells in tableview, except image view cell.

 tableview.estimatedrowheight = 100  tableview.rowheight = uitableviewautomaticdimension 

i want image tall wants, maintain image's aspect ratio , fill width. set image view's constraints pinned cell's frame using auto layout , set image views contentmode aspect fit. set uiimageview's background red. , cell above white. actual image black down below.

enter image description here

when that, cell has 100 px above image , 100px below. images size want. has had same issue?

because red space isn't same size , lot taller when have big image in there, believe layout thinks height should actual height of image, without aspect fit constraint.

thanks help!

i want image tall wants, maintain image's aspect ratio , fill width. set image view's constraints pinned cell's frame using auto layout , set image views contentmode aspect fit.

you can't auto layout. because uiimageview's intrinsic content size image's full size.

instead, calculate appropriate height , set when set image:

let imageviewwidth : cgfloat = // width want… imageheightconstraint.constant = image.size.height / image.size.width * imageviewwidth; 

note fail if have 0x0 image due division zero. if that's possible in app, check case , set height constant 0.

at point, reload row table view recalculate height.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -