ios - Xcode 6 - iOS8 - Auto Layout how to set constraint priorities right -


i'm trying use auto layout dynamically size uitableviewcell heights. basic cell design, labels in row, i've managed achieve want. can't working following:

setup

  • i'm using swift , xcode 6.4 targeting ios8 , above.
  • tableview row height set uitableviewautomaticdimension.
  • estimated height tableview set 100, should close final height.
  • the title's vertical hugging priority set low (250).
  • didn't change other elements hugging , compression priority.

here's prototype cell:

prototype cell

the image left has fixed height. title text should grow fit complete text. it's label rows set 0. subtitle should not grow because short text.

my constraints setup

  • for image leading , top constraint set 18. trailing constraint title , subtitle label set 18. bottom constraint set 18 priority low (249).
  • for title label top , trailing constraint superview set 18. leading constraint image 18. bottom constraint subtitle 0.
  • for subtitle label top constraint title label 0. trailing space superview 18. leading constraint image 18. bottom constraint superview 18 priority low (250).

the problem

no matter what, want bottom space superview 18 units. means, if text's (title + subtitle) height less image's height. image's bottom constraint should ensure 18 unit bottom margin. if title grows in height , total text higher image, subtitle's bottom constraint should ensure 18 unity bottom margin , image's bottom constraint should ignored.

i'm thankful suggestions how solve this, because i'm @ point, i'm punching in random values constraints...

update

please see marked answer on how setup constraints achieve layout needed. if cells not layout on tableview's first load, please se question workaround: ios 8 auto height cell not correct height @ first load

firstly, uitableviewautomaticdimension despite name isn't documented auto tableview row heights. don't implement heightforrowatindexpath , implement estimatedheightforrowatindexpath have.

to address layout problem, not priority issue problem constraints. because have fixed top , bottom constraint image, cell never grow larger image + 36pt. solution make top , bottom constraints image >= rather =.

after doing this, find there red warnings in ib ambiguous constraints. because greater or equal constraints, layout can't determine correct y position of image view. solution: add center y in superview constraint imageview.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -