Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 Example
Octocat-spinner-32 Source
Octocat-spinner-32 Tests
Octocat-spinner-32 .gitignore
Octocat-spinner-32 FTAssetRenderer.podspec
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.markdown
README.markdown

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.

Something went wrong with that request. Please try again.