Merge pull request #283 from andyscott/feature-template-image-mod-block

Add image modification block to render template images w/ tint.
This commit is contained in:
Nadine Salter 2015-02-03 14:13:57 -08:00
commit 3b8de5cf52
2 changed files with 29 additions and 0 deletions

View File

@ -137,4 +137,16 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
*/
asimagenode_modification_block_t ASImageNodeRoundBorderModificationBlock(CGFloat borderWidth, UIColor *borderColor);
/**
* @abstract Image modification block that applies a tint color à la UIImage configured with
* renderingMode set to UIImageRenderingModeAlwaysTemplate.
*
* @param tintColor The color to tint the image.
*
* @see <imageModificationBlock>
*
* @returns An ASImageNode image modification block.
*/
asimagenode_modification_block_t ASImageNodeTintColorModificationBlock(UIColor *color);
ASDISPLAYNODE_EXTERN_C_END

View File

@ -373,3 +373,20 @@ extern asimagenode_modification_block_t ASImageNodeRoundBorderModificationBlock(
return modifiedImage;
};
}
extern asimagenode_modification_block_t ASImageNodeTintColorModificationBlock(UIColor *color)
{
return ^(UIImage *originalImage) {
UIGraphicsBeginImageContextWithOptions(originalImage.size, NO, originalImage.scale);
// Set color and render template
[color setFill];
UIImage *templateImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[templateImage drawAtPoint:CGPointZero];
UIImage *modifiedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return modifiedImage;
};
}