Tag Archive for 'transparent'

iPhone – transparent imageview tint

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

The .h file:

#import <UIKit/UIKit.h>

@interface UIBlendableImageView : UIView

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

@end

The .m file:

#import "UIBlendableImageView.h"
#import <QuartzCore/QuartzCore.h>

@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