Tag Archives: image

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

Changing background image of UINavigationBar with CALayer

Adding a background image to a navigation bar can be done using categories, however I think it is not too elegant, and difficult to modify in application. (though sometimes it is the only solution)
The following code sets the background image using the layer of navigationbar view:
self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"background.png"].CGImage;

Source: Stackoverflow.com