iPhone UIBarButtonItem alpha of button image

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 release];

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

Answers


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);

Need Your Help

struts2 send html text back in actionerror or action message

java html struts2

In my web application I want to send some text back in the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.