[ANN] CHLayoutManager
[ANN] CHLayoutManager
- Subject: [ANN] CHLayoutManager
- From: Dave DeLong <email@hidden>
- Date: Sun, 15 Aug 2010 13:59:02 -0600
Hey everyone,
At work the other day I was pining for a CALayoutManager that worked on NSViews, because we're localizing our UI in code and have to do some simple rearrangement to support long button names, etc. Shifting things around in code is possible, though tedious, even with category methods to make it easier.
So I've written "CHLayoutManager", which is pretty much a clone of CALayoutManager for NSViews. This means I can now add "constraints" to my views, such as: "this button must stay 10 pixels to the right of this other button", and as the other button is resized/moved, this button also is resized/moved.
CHLayoutManager has some nice advantages over its CoreAnimation counterpart:
1. You don't have to specify a layout manager for views. All views use the same layout manager singleton.
2. You are not limited to a maximum number of constraints on views. You can have 100 constraints, and they'll all be evaluated in the order they were added.
3. You can have much finer control over constraint transformations by supplying an NSValueTransformer or a block to the constraint.
I've posted the code (MIT license) on github, available here: http://github.com/davedelong/CHLayoutManager
Included in the code is a little demo application that shows how you can use CHLayoutConstraints. There's also an example of a block-based constraint and an NSValueTransformer-based constraint.
The code is compatible with 10.5+ systems (the block code is conditional on NS_BLOCKS_AVAILABLE). Unfortunately, it doesn't look like this will be ported to iOS devices anytime soon, since it relies on NSViewFrameDidChangeNotification, which does not have an iOS counterpart (rdar://8312043).
If you have any comments or suggestions, please let me know!
Cheers,
Dave DeLong
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden