tags:

views:

779

answers:

1

I have used the code below to create a button on the nav bar with an image.

I can see the image but I can also see the border of the button around it. My question is, how can I get rid of the button border. All I want to see is the image on the nav bar, no border.

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 to read further or examples appreciated.

+2  A: 

Here's a code fragment from one of my current projects. It loads an image with transparency for a 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];
Shaggy Frog
Thanks Shaggy Frog. I added this line to make it do something when pressed.[settingsButton addTarget:self action:@selector(openSettings:) forControlEvents:UIControlEventTouchUpInside];
butchcowboy
I had that line in there but removed it -- I guess I should have left it in. :)
Shaggy Frog