tags:

views:

911

answers:

1

Hi,

I have to have two buttons on the right side of the navigation bar. So i created a tool bar and added two bar button items to its content view. Like below.

UIBarButtonItem *shareButton = [[UIBarButtonItem alloc]
         initWithImage:[UIImage imageNamed:@"share-icon-32x32.png"]
         style:UIBarButtonItemStyleBordered
         target:self action:@selector(showShare)];

 shareButton.width = 30.0f;
 [buttons addObject:shareButton];
 [shareButton release];

where buttons is an array holding the button objects.

Like wise i have another barbutton item like below

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
           initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
           target:self
           action:@selector(addDescription)];

  addButton.style = UIBarButtonItemStyleBordered;
  [buttons addObject:addButton];
  [addButton release];

Now add the array to the toolbar like below

[toolbar setItems:buttons animated:YES];
 [buttons release];

and add it to the rightBarButton like below

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
             initWithCustomView:toolbar];
 [toolbar release];

I am getting two bar button items on the right bar but i am not able to get the image displayed on to the share button item. Its just a white patch. Can any body tell me what am i doing wrong or how to get the image displayed.

Regards,

Syed Yusuf

+1  A: 

From the docs for initWithImage:style:target:action::

The alpha values in the source image are used to create the images—opaque values are ignored.

This means that UIKit uses the alpha channel of your image, not the RGB pixel values. The image you provided is probably completely opaque (has no transparency) and initWithImage:style:target:action: interprets this as a white square. You must save your image with an alpha channel that defines the shape of your icon.

Ole Begemann
Hi Begemann,Thanks a lot. Yes i was using an opaque image. I used an equivalent gray-scaled image and it did show up in the nav bar.Regards,Syed Yusuf
U'suf
U'suf, please mark the answer as accepted if you feel it answers the question.
Ole Begemann