|This is a fairly simple category add-on to NSImage that allows you to draw a given image with stretching applied only to its middle while respecting the cap sizes on the corners. I tried to add support for having non-caps in some cases, but I honestly can't think of a scenario where that would be useful, so it's untested (and, as a result, there are a number of conditionals in the drawing code that might break it if you don't specify all four caps).|
Essentially, it lets you take this image:
And draw it like so:
The methods are fairly simple, so I don't think I need to explain them here.
FYI: this code is licensed under the zlib/libpng license. This basically means you can do whatever the hell you want with it provided you don't claim you wrote it, but you should ask your lawyer if you have any questions.