ios - UITableViewCell not shrinking to wrap UIImageView -


i have tableview first element fixed aspect ratio header image. embedded uiimageview inside uitableviewcell's content view. desired outcome entire cell adopting size of image. tried couple of things, first of all, pinning 4 edges of uiimageview parent content view , setting aspect ratio desired value (2h 3w). setup aspect ratio constraint gets ignored , image view takes height of cell, shrinks asset. next, tried remove bottom constraint. result, aspect ratio respected, cell height larger of image view.

my question is, can make cell shrink wrap height of image view using auto layout?

can make cell shrink wrap height of image view using autolayout?

yes can, there trick. uitableviews have fixed height cells. if want variable height must implement uitableviewdelegate method

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath; 

if cell constraints setup (and mean if instead of cell had uiview, it's size defined it's content), able this:

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { mycell *cell = [tableview dequeuereusablecellwithidentifier:kidentifier]; // setup cell image return [cell systemlayoutsizefittingsize:uilayoutfittingcompressedsize].height; } 

the problem is, if retrieving images web, there no possible way know size of image without loading it. if using local images, should work.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -