iphone - 我如何更改导航栏的背景颜色

标签 iphone uinavigationcontroller navigation uinavigationbar uinavigationitem

在我的导航栏中,我在左侧和右侧位置有两个按钮,在导航标题处有一个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/

相关文章:

ios - 如何在 Swift 中将新单元格插入到 UITableView 中

iphone - 拒绝等待开发者发布的应用程序

iPhone 中心文本 ShowTextAtPoint

ios - 导航 Controller 呈现在我导航到的 View 上

python - 可订购 Bug 中的鹡鸰可订购?

django - Django 中的层次结构树导航

iphone - iOS : If app is not running in background, 调用 openURL 在启动时崩溃应用程序

ios - UINavigationView - 按下后退时停止播放视频

php - 我只想在顶级导航中的 anchor 后显示图像

ios - Storyboard导航 Controller 和标签栏 Controller