ios - Can I use NSLayoutConstraints to keep a UIView's subviews equally spaced regardless of later adding or removing from the subviews array? -


i'd have uiview where, every time add or remove subviews subviews array, whichever subviews happent in array still equally spaced.

for example, if have subviews , b spaced 10 points appart, so:

[a]-10-[b]

and add view c, views in subviews should automatically laid out this:

[a]-10-[b]-10-[c]

if, remove view b, gap in between , c should update once again 10 points:

[a]-10-[c]

i know can use nslayoutconstraint create type of constraint between 2 known views, , guess set kvo each time array changes cycle through subviews , re-apply constraint i'm wondering if there automatic way of doing it.

make sure code calculates constraints based on current subviews in updateconstraints:

- (void)updateconstraints {     [super updateconstraints];     // put code here } 

then need call setneedsupdateconstraints whenever add/remove subview.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -