I've added a button to a lower toolbar like this:
UIImage *locationImage = [UIImage imageNamed:@"193-location-arrow.png"];
UIBarButtonItem *locationButton = [[UIBarButtonItem alloc] initWithImage:locationImage style:UIBarButtonItemStyleBordered target:self action:@selector(updateCurrentLocation)];
NSArray *items = [[NSArray alloc] initWithObjects:locationButton,nil];
[toolbar setItems:items];
[items release];
[locationButton release];
This works great, the alpha of the image is picked up fine, the button displays like this:
So, I took this code and modified slightly to create a button in my navigation bar:
UIImage *favouriteImage = [UIImage imageNamed:@"28-star.png"];
UIBarButtonItem *favouriteButton = [[UIBarButtonItem alloc] initWithImage:favouriteImage style:UIBarButtonItemStyleBordered target:self action:nil];
self.navigationItem.rightBarButtonItem = favouriteButton;
[favouriteButton relea开发者_开发技巧se];
The alpha doesn't seem to be picked up on this one - it looks greyed out:
Is there something I need to set when using custom images in the navigation bar?
Thanks and Regards,
Rich
You could convert the image to white with a few lines of code:
CGRect imageRect = CGRectMake(0, 0, inImage.size.width, inImage.size.height)
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(data1, imageRect.size.width, imageRect.size.height, 8, imageRect.size.width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGContextClipToMask(context, imageRect, inImage.CGImage);
CGContextSetRGBFillColor(context1, 1, 1, 1, 1);
CGContextFillRect(context, imageRect);
CGImageRef finalImage = CGBitmapContextCreateImage(context);
UIImage *returnImage = [UIImage imageWithCGImage:finalImage];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
CGImageRelease(finalImage);
精彩评论