Cocoa autolayout constraint - programmatic padding of variable number of views -


i want able add new views superview keep constant vertical distance between each other. tried programmatically set constraint each view not figure out how it. problem not know beforehand number or relative position of views.

is there way programmaically set constraint each view regardless of whatever other views neighbor, autolayout keep constant spacing between views?

possible short code snippet looking for:

nsmutablearray* newverticalconstraints = [nsmutablearray array]; uiview* firstview = nil; uiview* secondview = nil; uiview* superview = <your container view>; nsarray* subviews = [superview subviews]; if ([subviews count] > 0) {     firstview = [subviews objectatindex:0];     // add first constraint     [newverticalconstraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"v:|-10-[firstview]" options:0 metrics:nil views:nsdictionaryofvariablebindings(firstview)]];      (int = 1; < [subviews count]; i++) {         secondview = [subviews objectatindex:i];         [newverticalconstraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"v:[firstview]-10-[secondview]" options:0 metrics:nil views:nsdictionaryofvariablebindings(firstview,secondview)]];         firstview = secondview;     }      // add last constraint     [newverticalconstraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"v:[firstview]-10-|" options:0 metrics:nil views:nsdictionaryofvariablebindings(firstview)]];      [superview removeconstraints:self.verticalconstraints];     [superview addconstraints:newverticalconstraints];     // save vertical constraints able remove them     self.verticalconstraints = newverticalconstraints; } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -