在我的导航栏中,我在左侧和右侧位置有两个按钮,在导航标题处有一个segetControll View 。 我想将导航栏的背景颜色更改为黑色,但其上项目的颜色将是另一种颜色。 我该怎么做? 我尝试将导航栏的色调颜色更改为黑色。 但我表明,segmentedControll 和导航栏上的按钮的颜色也更改为黑色。
提前致谢。
最佳答案
尝试将对象设置为导航栏的 subview 。
设置色调颜色
UINavigationController *theNavigationController = [[UINavigationController alloc] initWithRootViewController: aFeedControler];
theNavigationController.navigationBar.tintColor = [UIColor blackColor];
将segmentedControl添加为viewControllers中的 subview ,如下所示:
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;
对于按钮,您应该尝试创建 UIButtons 而不是 UIBarButtonsItems 并将它们添加为 subview 。如果您创建 UIBarButtonsItems 并像这样添加它们 self.navigationItem.rightBarButtonItem = tempButton;您将获得您所看到的效果。
如果您将它们添加为 subview ,您不应该遇到您提到的问题..希望它有帮助。
关于iphone - 我如何更改导航栏的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1672599/