Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone -- Layout manager for UIViews?

Tags:

layout

iphone

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?

like image 312
morgancodes Avatar asked Feb 04 '10 21:02

morgancodes


People also ask

What is iOS auto layout?

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.

What is layout margin iOS?

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.

Does Apple have a design system?

Apple Design Resources Design apps quickly and accurately by using Sketch, Photoshop, and XD templates, guides, and other resources.

What is Layoutmarginsguide?

A layout guide representing the view's margins.


2 Answers

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.

like image 94
johnnyd Avatar answered Oct 13 '22 19:10

johnnyd


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.

like image 31
Joe Cannatti Avatar answered Oct 13 '22 18:10

Joe Cannatti