I'm not sure whether "layout manager" is the correct term, but i'm looking for a way to get UIViews to flow into thier parent view, like left-floated div's would in an HTML page. Is there an easy way to do this, either via the iPhone api's or something external?
Auto Layout is the preferred technology to define layouts for user interfaces on iOS and macOS. Its goal: To make it easy for you to create user interfaces that adapt automatically to different screen sizes and orientations.
Layout margins provide a visual buffer between a view's content and any content outside of the view's bounds. The layout margins consist of inset values for each edge (top, bottom, leading, and trailing) of the view.
Apple Design Resources Design apps quickly and accurately by using Sketch, Photoshop, and XD templates, guides, and other resources.
A layout guide representing the view's margins.
After doing some searching I found this: http://code.google.com/p/layoutmanagers/ Last Development was in Dec 2009 but at first glance, it seems like it can still be applicable to current versions of iOS.
There is nothing like this really build into the sdk, but it shouldn't be too hard to get the behavior you're after. Just call
NSArray *subs = [parentView subviews];
to get all of the subviews already present. Loop through them like this
CGRect leftMostViewsFrame = nil;
for(UIView *cur in subs){
CGRect where = cur.frame;
//find the left most frame for a given X coord
}
and place your new view next to it
newView.frame = CGRectMake(leftMostViewsFrame.origin.x + leftMostViewsFrame.size.width,
[parentView addSubview:newView];
......
You can write it much more cleanly than that and there is a lot more checking and reasoning you need to do to get all the behavior of float, but that is the basic approach i would take. I don't know if there is a third party lib you could use or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With