Category for trimming transparent pixels of an UIImage object.
Objective-C
Latest commit 6856b68 Nov 13, 2013 @mac-cain13 mac-cain13 Merge pull request #6 from Clstroud/master
Refactored inset calculation into a separate method, altered sensitivity in determining what constitutes a transparent pixel (optional).

README.md

UIImage-Trim

Category for trimming transparent pixels of an UIImage object.

How to use

Add the UIImage+Trim files to your project. Include UIImage+Trim.h in the files where you want to trim your images.

Trimming is pretty straightforward:

[yourImage imageByTrimmingTransparentPixels];

Optionally, you may want to consider any non-opaque pixels as being transparent (for instance, cropping out a light drop shadow). This can be achieved by using the alternate method:

[yourImage imageByTrimmingTransparentPixelsRequiringFullOpacity:YES];

Additionally, if you merely desire to know the UIEdgeInsets of the transparency around the image, you may want to use the following:

[yourImage transparencyInsetsRequiringFullOpacity:YES];

This call works based on the same principles as the "advanced" trim method, with the boolean dictating whether non-opaque pixels should be considered transparent.