views:

744

answers:

2

Hi developer, In my navigation bar i have two button at left and right position and a segmentetControll view at navigation title. I want to change the background color of the navigation bar to black but thae color of the items on it will be another color. how can i do it? I try to chnage the tintColor of the navigationBar to black. but i show that the color of the segmentedControll and the button on the navigationBar also changed to black.

thanks in advance.

+1  A: 

You should search the forum before posting a question. http://stackoverflow.com/questions/1636794/how-to-change-color-of-the-uinavigationbar-buttons-on-it/1636828#1636828

Morion
I had seen that link before.but that was not my solution.
faisal
A: 

try to set the objects as subviews to the navigationBar.

Set the tint color

UINavigationController *theNavigationController = [[UINavigationController alloc] initWithRootViewController: aFeedControler]; 
theNavigationController.navigationBar.tintColor = [UIColor blackColor];

Add the segmentedControl as a subview in the viewControllers like this:

 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:[UIImage imageNamed:@"segment_check.png"],
[UIImage imageNamed:@"segment_search.png"],
[UIImage imageNamed:@"segment_tools.png"], nil]];
    CGRect frame = CGRectMake(0,0, 200,40);
    segmentedControl.frame = frame;
    [segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
    segmentedControl.selectedSegmentIndex = 1; 
    self.navigationItem.titleView  = segmentedControl;

For the buttons you should try creating UIButtons not UIBarButtonsItems and add them as subviews also. If you create UIBarButtonsItems and add them like this self.navigationItem.rightBarButtonItem = tempButton; you will get the effect that you saw.

if you add them as subviews you shouldn't have the problem you mentioned.. hope it helps.

SorinA.
Thanks for your solution.
faisal
if the problem was resolved close the question.
SorinA.