Artem Stepanenko Artem Stepanenko - 4 months ago 55
iOS Question

Modify UIImage renderingMode from storyboard/xib file

Is it possible to modify a

UIImage
's
renderingMode
from a storyboard or xib editor?

The goal is to apply the
UIImageView
tintColor
to the actual image.

Answer

Here's how you can do it in .xib or storyboard files:

Create a category on UIImageView:

@interface UIImageView (Utils)

- (void)setImageRenderingMode:(UIImageRenderingMode)renderMode;

@end

@implementation UIImageView (Utils)

- (void)setImageRenderingMode:(UIImageRenderingMode)renderMode
{
    NSAssert(self.image, @"Image must be set before setting rendering mode");
    self.image = [self.image imageWithRenderingMode:renderMode];
}

@end

Then in the Identity Inspector in the xib file, add a runtime attribute:

enter image description here

Comments