views:

37

answers:

2

Hello

Can I show a black style UIBarButtonItem in my view without the underneath UIToolBar?

The UIToolBar always has a kind of border thing, I want the system UIBarButtonItem in black just like a black standard cancel button, but not the UIToolBar

How can I do it?

Thanks

A: 

I haven't exactly done anything like that, but I suggest you could somehow set all the UIToolBar's subviews alpha to zero except for the UIBarButtonItem . Just leave the UIBarButtonItem visible.

UIToolBar inherits from UIView, so my first try would be to set its backgroundColor to clearColor.

Bersaelor
A: 

there is a cheeky hack that will help you with this.

you want to use a UISegmentedControl with style set to UISegmentedControlStyleBar and only one item. You also need to setMomentary to yes - to make it behave like a button:

UISegmentedControl *myCustomButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Hello",nil]];
[myCustomButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[myCustomButton setTintColor:[UIColor blackColor]];
[myCustomButton setMomentary:YES];
[self.view addSubview:myCustomButton];

This will give you a button that looks like a UIBarButtonItem that you can add to your normal view as if it were a button. You can add a target and an action as well. :)

This is what you get: something like this:

alt text

Thomas Clayson
Thanks Thomas,it worked. but the problem is that if I click on it, it won't have any highlight features, i mean some effects to show this button is pressed. How can I add a highlight feature?
Jack
it should do... thats what the `setMomentary` does, it shows a highlight momentarily, like a normal button... try setting the tintColor to `darkGrayColor` and see if makes any difference. Maybe `blackColor` is too dark, there isn't any darker left. :p
Thomas Clayson