ios - autolayout aspect ratio imageview in tableviewcell -


i have custom tableviewcell imageview inside it. layout such:

layout

i want use autolayout calculate height of cell in method

cgsize size = [cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize];

so set constraints this

tree

basically these constraints pin each element edge of superview or view above/below.

the problem there 1 more constraint want add imageview's aspect ratio. want set imageview's height half of width. if directly set aspect ratio constraint 2:1 unable simultaneously satisfy constraints error. tried change priority high , still no luck.

can achieve using autolayout?

the reason why constraints work , automatic height correctly calculated ui elements have own intrinsic size (the size make fit content).

therefore, imageview has size fit image put inside. can't both use intrinsic size , specify own (even if want change 1 of dimensions).

a solution see have static height constraint on uiimageview, plus aspect ration 1 width. in code set constant height constraint image.size.height value.

[self.imageheightconstraint setconstant:self.imageview.image.size.height]; [self.view layoutifneeded]; 

in way sort of keep half intrinsic size (just height) , custom width.

hope explanation made sense 😊. let me know if have questions though.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -