0

I want my leftBarButtonItem to be a red button. I haven't figured out how to do that. I'm using the following code to construct the navigation bar and button. Any help is appreciated. lq

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
navBar.barStyle = UIBarStyleBlack; 
navBar.translucent = YES;
[self.view addSubview:navBar];
[navBar release];

UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] 
initWithTitle:@"Clear"
style:UIBarButtonItemStyleBordered
target:self 
action:@selector(myAction:)];

navItem.leftBarButtonItem = clearButton;
[navBar pushNavigationItem:navItem animated:false];
[navBar setDelegate:self];    
[navItem release];
[clearButton release]; 
Lauren Quantrell
  • 2,647
  • 6
  • 36
  • 49

1 Answers1

1

Maybe you will find a nicer solution in this posting at Stack Overflow or you can go the way using a UISegmentedControl

UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Clear", nil]] autorelease];
button.momentary = YES;
button.segmentedControlStyle = UISegmentedControlStyleBar;
button.tintColor = [UIColor redColor];
...
UIBarButtonItem *clearButton = [[UIBarButtonItem alloc] initWithCustomView:button];

navItem.leftBarButtonItem = clearButton;
Community
  • 1
  • 1
disco crazy
  • 31,313
  • 12
  • 80
  • 83