MGSplitViewController is an open source replacement for UISplitViewController, with various useful enhancements.
Here’s a demonstration video hosted on YouTube. It’s better if you watch it in full HD.
I wrote MGSplitViewController for my own use, but I’m making it available (as usual) for the benefit of the iOS developer community, because I care about this community and about the platform.
If you make use of MGSplitViewController, a Paypal donation (or something from my Amazon.co.uk Wishlist) would be very much appreciated. Appropriate links can be found here.
It’s taken a fair bit of work to refine the code to a flexible, reusable state, and I hope you’ll find it useful in your own projects. It’s my goal that it should save you many hours or days of work.
Please note that, since split-views are commonly used for “Master-Detail” interfaces, I call the first sub-view the “master” and the second sub-view the “detail”.
- By default, MGSplitViewController mimics the appearance and (complete) behaviour of UISplitViewController, including its delegate API. It accepts two UIViewControllers (or subclasses thereof).
- Allows toggling the visibility of the master view in either interface-orientation; i.e. you can have master-detail or detail-only in either landscape and/or portrait orientations (independently, and/or interactively).
- Allows choosing whether the split orientation is vertical (i.e. left/right, like UISplitViewController), or horizontal (master above, and detail below). You can toggle between modes interactively, with animation.
- Allows choosing whether the master view is before (above, or to left of) the detail view, or after it (below, or to the right).
- Allows you to choose (and change) the position of the split, i.e. the relative sizes of the master and detail views.
- Allows you to enable dragging of the split/divider between the master and detail views, with optional constraining via a delegate method.
- Allows you to choose the width of the split between the master and detail views.
- Preset “divider styles”: one for non-draggable UISplitViewController-like dividers, and one for draggable, thicker style with a grip-strip.
- Allows you to substitute your own divider-view (an MGSplitDividerView subclass), used to draw the split between the master and detail views.
Getting the Code
MGSplitViewController is hosted on github, for ease of sharing; you can get the code here.
If you find it useful, it’d be much appreciated if you leave a comment to that effect here, and (ahem) note the Donations section above. Relax, that’s the last time I’ll mention it.
How to use
The “MGSplitViewController.h” header file (and the sample project) should be self-explanatory. It’s recommended that you use the project as a reference.
Interface Builder support
At time of writing, MGSplitViewController cannot be quite as elegantly visually configured like UISplitViewController using Interface Builder.
You can, however, (and it is recommended that you do) create an instance of it in a xib, and connect the masterViewController and detailViewController outlets to the required view-controllers.
License and Warranty
The license for the code is included with the project; it’s basically a BSD license with attribution.
You’re welcome to use it in commercial, closed-source, open source, free or any other kind of software, as long as you credit me appropriately. If you require a different open source license, please contact me (details below). If you need a license without the attribution requirement, a fee will be payable.
The MGSplitViewController code comes with no warranty of any kind. I hope it’ll be useful to you (it certainly is to me), but I make no guarantees regarding its functionality or otherwise.
Support / Contact / Bugs / Features
I can’t answer any questions about how to use the code, but I always welcome emails telling me that you’re using it, or just saying thanks.
If you create an app which uses the code, I’d also love to hear about it. You can find my contact details here.
Likewise, if you want to submit a feature request or bug report, feel free to get in touch. Better yet, fork the code and implement the feature/fix yourself, then submit a pull request.
You can keep up to date with what I’m working on by following me (@mattgemmell) on Twitter, and you can see my apps (or enquire about hiring me for your projects) at my business site, Instinctive Code.
Enjoy the code!