Tag Archives: subclass

iPhone – transparent imageview tint

Drop-in solution for a tintable/blendable “imageview”:

The .h file:

#import 

@interface UIBlendableImageView : UIView

- (id)initWithImage:(UIImage*)image andTintColor:(UIColor*)tintColor;

@end

The .m file:

#import "UIBlendableImageView.h"
#import 

@implementation UIBlendableImageView

- (id)initWithImage:(UIImage*)image andTintColor:(UIColor*)tintColor
{
    self = [super initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    if (self) {
        UIImageView *maskImageView = [[[UIImageView alloc] initWithImage:image] autorelease];
        [maskImageView setFrame:[self bounds]];
        [[self layer] setMask:[maskImageView layer]];
        [self setBackgroundColor:tintColor];
    }
    return self;
}

@end