A small library for semantic layout of UIViews.
Objective-C Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
DemoApp Removing unnecessary image files from project. Apr 24, 2017
POViewFrameBuilder Make po_frameBuilder a method instead of a property. Fixes #5 Oct 30, 2013
.gitignore POViewFrameBuilder and DemoApp Nov 11, 2012
LICENSE
POViewFrameBuilder.podspec Updated podspec to version 1.0.2 Oct 30, 2013
README.md Updated README to add update: method Dec 7, 2012

README.md

POViewFrameBuilder

POViewFrameBuilder aims to provide a simple way to layout UIViews programatically while maintaining the semantics and readability of the code. It lets you modify a view's frame by chaining a series of readable layout methods. It reduces the amount of frame calculation code and keeps the intent of your layout clear. A handy tool for your average layoutSubviews, animation block etc.

It is by no means complete, but rather contains a number of methods I have happened to need at various occasions. Feedback and pull requests are very welcome.

Usage

The following two examples give you a brief introduction on how POViewFrameBuilder can be used. Just include the UIView+POViewFrameBuilder.h category where you want to use it, and then you can access the po_frameBuilder convenience property to instantiate a frame builder for any UIView subclass.

Resizing a view:

[view.po_frameBuilder setWidth:100.0f height:40.0f];

Moving a view to be centered within it's superview:

[view.po_frameBuilder centerInSuperview];

You can combine these methods to your own liking:

[[view.po_frameBuilder setWidth:100.0f height:40.0f] centerHorizontallyInSuperview];

Demo

The DemoApp project shows how POViewFrameBuilder can be used in animation blocks. One thing to note is that by default, the automaticallyCommitChanges property is set to YES. This means that the frame changes are committed after every modifying method in the chain. However, having multiple frame changes in an animation doesn't work, and the view ends up jumping around. To avoid this, begin the method chain by calling disableAutoCommit and finish the series of changes by calling the commit method, which will update the view's frame:

[[[[view.po_frameBuilder disableAutoCommit] setWidth:100.0f height:40.0f] centerHorizontallyInSuperview] commit];

Thanks to @rsobik, there is now also a shorter and more readable way to create these transactions:

[self.squareView.po_frameBuilder update:^(POViewFrameBuilder *builder) {
	[builder setWidth:100.0f height:40.0f];
	[builder centerHorizontallyInSuperview];
}];