KJGridLayout

Xcode's Interface Builder is a pretty good user-interface layout tool, especially for simple situations. However, it is not the best tool for every job. Sometimes you have to write code to dynamically create user interface elements or to move them around as the view is resized.

When you do this, you find that iOS doesn't help you much beyond some rudimentary autoresizing options. While iOS 5 does provide some autolayout features, they are limited, and they don't help at all if you need to support earlier versions of iOS.

I had a need to do a grid-based layout in an iOS app. I hoped to find a grid-layout component like one would find in Android or WPF, but there is no such thing built into iOS.

I also couldn't find any third-party implementations. I found a few posts and samples for making a grid-like UITableView, but I wanted a way to lay out things in a grid in a plain-old UIView.

So I decided to write my own grid-layout thingees for iOS.

The results are the KJGridLayout class and the KJGridLayoutView class, which you can find on GitHub. Check out the README and feel free to use them yourself. I hope someone finds this stuff useful.

© 2003-2023 Kristopher Johnson