-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|558|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Graphical Effects


 
Cower
Created : 06 March 2011
 
System : Mac
Language : C#

NSImage Nine-Part Drawing

A category that adds simplified nine-part image drawing to NSImage

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.




 

Comments