Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Latest commit

 

History

History
53 lines (34 loc) · 2.62 KB

README.markdown

File metadata and controls

53 lines (34 loc) · 2.62 KB

FTAssetRenderer

Create image assets, at runtime, in any color when used as mask and/or at any resolution when it’s a PDF.

Install

If you’re using CocoaPods, add the following to your Podfile:

pod 'FTAssetRenderer'

Otherwise, simply add the files from the Source dir to your project.

Usage

If you have a bitmap image that’s used as a mask to generate images in different colors, then you can use it like so:

FTImageAssetRenderer *renderer = [FTAssetRenderer rendererForImageNamed:@"my-icon" withExtension:@"png"];
renderer.targetColor = [UIColor redColor];
UIImage *result = [renderer imageWithCacheIdentifier:@"red"];

If, on the other hand, you have a vector based PDF image, you should generally indicate the size at which it should be rendered as well:

FTPDFAssetRenderer *renderer = [FTAssetRenderer rendererForPDFNamed:@"my-scalable-icon"];
renderer.targetColor = [UIColor blueColor];
renderer.targetSize = CGSizeMake(123, 456);
UIImage *result = [renderer imageWithCacheIdentifier:@"without-preserving-aspect-ratio"];

In the above example, an explicit width and height is given for the result image, which might lead to the image not preserving its original aspect ratio. To ensure the ratio is preserved, a few convience methods are available:

  • -[FTPDFAssetRenderer fitWidth:] will make the result image as wide as the given width, while the height is based on it.
  • -[FTPDFAssetRenderer fitHeight:] will make the result image as high as the given height, while the width is based on it.
  • -[FTPDFAssetRenderer fitSize:] will make the image as large as possible, inside the bounding size, but without cropping any part of the image, thus only fully covering one of the two sides.

By default, the resulting image is cached on disk. For each different target color, a different cache identifier should be used. For instance, for controls you might use identifiers such as normal, highlighted, and selected.

Acknowledgements

Based on work by:

Thanks to Peter Steinberger (of PSPDFKit fame) for his invaluable advice during the creation of this library.