IPhone SDK: how to add image to UIBarButton?

I used the code below to create a button on the image navigation bar.

I see the image, but I also see the border around it. My question is how can I get rid of the border of a button. All I want to see is an image in the navigation bar, no frame.

UIBarButtonItem *settingsBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_prefs.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openSettings:)]; [[self navigationItem] setLeftBarButtonItem:settingsBtn]; [settingsBtn release]; 

Thanks in advance. Any pointers, links for further reading, or examples.

+6
iphone
source share
1 answer

Here's a snippet of code from one of my current projects. It loads an image with transparency for UIBarButtonItem :

 UIImage* image = [UIImage imageNamed:@"some-image.png"]; CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height); UIButton* someButton = [[UIButton alloc] initWithFrame:frame]; [someButton setBackgroundImage:image forState:UIControlStateNormal]; [someButton setShowsTouchWhenHighlighted:YES]; UIBarButtonItem* someBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:someButton]; [self.navigationItem setRightBarButtonItem:someBarButtonItem]; [someBarButtonItem release]; [someButton release]; 
+20
source share

All Articles