NSImage + Nine-Part Drawing
So, something that’s slightly miffed me about NSImage is that drawing it in sections is a real pain in the ass. Unfortunate, but that’s what you get when Apple devotes all their time to iOS’s APIs and kind of neglects Mac OS. So, rather than sit around bitching like usual (something I restrict to IRC, thankfully [or unfortunately, if you’re on IRC with me]), I decided to write a quick category to fix this oversight.
Basically, this code is made so that if you take an image like
, you can render it like so:

Now, this code is not perfect. I would assume it’s not going to work if you pass a zero or smaller number as cap. There was code in there while I thought about letting certain caps be ignored, but it now just sits untested. Obviously, if you like it and want to fix that issue for me, that’d be great. However, I can’t really imagine a lot of scenarios where you need to ignore a certain cap (it’s not that I can’t imagine them, it’s just that there’re very few).
So, if you want to check out the code and see if you can find a use for it, head over to this gist to pick it up. It’s currently released under the zlib license, so I don’t think you need to worry about copyright issues and whatnot here.