Lukas
Lukas

Reputation: 2535

annotationView override drawRect, image with alpha

Hello i want to override drawrect in my custom annotationView, so when i write

[[_mapView viewForAnnotation:annotation] setNeedsDisplay]; 

my annotation view will be redrawn and i wouldn't have to remove the annotation and add it again.

here is my drawRect

- (void)drawRect:(CGRect)rect {
    UIImage* theImage = nil;
    if( _pinType == T_UNKNOWN ) theImage = [UIImage imageNamed:@"imgU.png"];
    else theImage = [UIImage imageNamed:@"imgK.png"];
    [theImage drawInRect:rect];
}

The problem is that my images are with alpha and the alpha part is black.

So maybe anyone knows the solution or some suggestions to this? I've read a lot of post about this, also using core graphics, but didn't find the solution..

Thanks in advance!

Upvotes: 3

Views: 897

Answers (2)

Rob Napier
Rob Napier

Reputation: 299455

Do you want this view to be partially transparent and display things under it? If so, use [self setOpaque:NO]. An opaque view's drawRect is responsible for drawing every pixel in the rectangle with a fully opaque color.

Upvotes: 3

alexmorhun
alexmorhun

Reputation: 1983

This function will be work correct for iOS 5.0. When you will use iOS version < 5.0, you'll got alpha part as black.

To try use another method for draw your images. I don't know for what you use this code. To try use:

UIImageView *image = [[UIImageView alloc] initWithImage: theImage];
image.opaque = NO;
[self.view addSubview: image];

Upvotes: 1

Related Questions