uilabel - IOS Label and View constraints height -


i confused constraints ios, i've read lot of articles, stuck, when tried set height constraints of uiview according uilabel content height. know common question, don't understand solutions. thought main thing in question constraint priority, can't set them properly. in 1 case, height of uiview wont change 0, , in other uilabel height not make sense.

so. i've got:

  1. uiview height constraint, , descendants constraints (below)
  2. uiimageview height=32, width=32, top=10, left=10, bottom>=10
  3. uilabel left uiimageview = 10, top=10, right=10, bottom=10

and want:

  1. if got text place in uilabel, want dynamic height of uiview according height of content size of uilabel.
  2. and if there no text place in uilabel, want set height of uiview equals 0 (hide uiview totally).

uiimageview - icon. if there no text, must shrink 0, if there text, must have height 32, top constraint 10, bottom constraint more or equals 10.

upd:

fix problem, adding height constraint programmatically. (don't this)

you can make constraints take full control of label,image , view heights, if set priorities correctelly.

  • set 4 vertical margins priorities less 1000 (lets 999)
  • set image height priority 999 too.
  • set lable vertical hugging priority 1000
  • set image height less or equal label height 1000 priority
  • set label height less or equal container view height multiplier 1: 10(or big number) priority 1000

like this

enter image description here

the view this

enter image description here

and this

enter image description here


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -