resize - iOS Auto Layout: 3 column label layout, with middle column having variable width -


i'm trying create thought easy using auto layout ios. i've been on days, bought book, , tried various keyword search combinations. done before , point me in right direction?

i want 3 uilabels, arranged in columns, middle 1 (which has more content) variable width depending on orientation of ipad.

i can work, once ipad rotates landscape portrait (and therefore reduces width available middle label) middle label content gets cut off. i.e. middle label height doesn't resize.

this want achieve: this want achieve

once rotate portrait: once rotate portrait

here constraints , view hierarchy: here constraints , view hierarchy

if give middle uilabel height constraint of 'less or equal to' 250 (the height needs show content in narrow portait mode), once ipad orientates landscape label content expands fit new width no longer aligns nicely tops of other labels on either side.

wrong vertical alignment wrong alignment

here's constraints on middle label constraints on middle label

(that height equal 250 has priority of 1, generated constraint cant rid of.)

i've tried many combinations of content hugging , compression resistance, sure that have been answer, i.e. requiring uilabel frame hug content. don't understand should.

ok, figured out after finding stackoverflow question: link answer
it's working have hoped

all had set line breaks 'word wrap' , update preferred width on device orientation, this

- (void)willanimaterotationtointerfaceorientation:(uiinterfaceorientation)interfaceorientation duration:(nstimeinterval)duration {     if (uideviceorientationislandscape(interfaceorientation)) {         self.middlelabel.preferredmaxlayoutwidth = 600;     } else {         self.middlelabel.preferredmaxlayoutwidth = 314;     } } 

so, sum up, combination of increasing content hugging, reducing priority of height constraint , updating preferredmaxlayoutwidth on device orientation. still, putting hardcoded values layout code feels wrong. can think of better way?


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -