Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode Can';t将导航栏颜色更改为白色_Xcode_Colors_Navigation - Fatal编程技术网

Xcode Can';t将导航栏颜色更改为白色

Xcode Can';t将导航栏颜色更改为白色,xcode,colors,navigation,Xcode,Colors,Navigation,我可以将导航栏设置为黑色或任何其他颜色,但当我尝试白色时,它只会设置为灰色。出于好奇,以下是我使用的代码: [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]]; 这是怎么回事?setbatintColor是一种色调,意思是它是有色的——这就是为什么你看到的是灰色而不是白色(如果不是白色的话)。如果要用纯色填充导航栏,请尝试使用setBackGroundColor: [[UINavigationBar appea

我可以将导航栏设置为黑色或任何其他颜色,但当我尝试白色时,它只会设置为灰色。出于好奇,以下是我使用的代码:

[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];

这是怎么回事?

setbatintColor
是一种色调,意思是它是有色的——这就是为什么你看到的是灰色而不是白色(如果不是白色的话)。如果要用纯色填充导航栏,请尝试使用
setBackGroundColor

[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
如果您仍然希望使用alpha值进行一些控制,则可以使用:

[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithWhite:1.0 alpha:1.0]];
从iOS 7、导航栏、选项卡栏和工具栏开始 (以下称为“条”)通过以下方式配置为半透明: 违约半透明条将其颜色与之前的灰色混合 将其与系统定义的alpha值相结合以生成最终结果 用于将条形图与其内容合成的背景色 覆盖


setbatintColor
是一种色调,意味着它是有色的——这就是为什么你看到的是灰色而不是白色(如果不是白色的话)。如果要用纯色填充导航栏,请尝试使用
setBackGroundColor

[[UINavigationBar appearance] setBackgroundColor:[UIColor whiteColor]];
如果您仍然希望使用alpha值进行一些控制,则可以使用:

[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithWhite:1.0 alpha:1.0]];
从iOS 7、导航栏、选项卡栏和工具栏开始 (以下称为“条”)通过以下方式配置为半透明: 违约半透明条将其颜色与之前的灰色混合 将其与系统定义的alpha值相结合以生成最终结果 用于将条形图与其内容合成的背景色 覆盖


找到了解决办法。只需将半透明设置为off即可

[[UINavigationBar appearance] setTranslucent:NO];

当我停下来想一想的时候,它应该是显而易见的。

找到了解决办法。只需将半透明设置为off即可

[[UINavigationBar appearance] setTranslucent:NO];

当我停下来思考时,它应该是显而易见的。

如果要设置单个条的颜色,请在.m文件中输入以下内容:

创建导航控制器:

UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
更改栏的颜色:

myNavigationController.navigationBar.backgroundColor = [UIColor blueColor];

如果要设置单个条的颜色,请在.m文件中输入以下内容:

创建导航控制器:

UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
更改栏的颜色:

myNavigationController.navigationBar.backgroundColor = [UIColor blueColor];

我创建了新类CustomViewController.swift,如下所示:

import UIKit

class CustomViewController: UINavigationController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        let nav = self.navigationBar
        nav.barStyle = UIBarStyle.black
        nav.barTintColor = UIColor.white
        //nav.tintColor = UIColor.white
        nav.backgroundColor = UIColor.white
        nav.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    }
}
除非我在另一个类中删除覆盖我更改的行,否则它不会起作用:

//nc.navigationBar.shadowImage = UIImage()
//nc.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "bar_background"), for: .default)

我创建了新类CustomViewController.swift,如下所示:

import UIKit

class CustomViewController: UINavigationController {

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        let nav = self.navigationBar
        nav.barStyle = UIBarStyle.black
        nav.barTintColor = UIColor.white
        //nav.tintColor = UIColor.white
        nav.backgroundColor = UIColor.white
        nav.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    }
}
除非我在另一个类中删除覆盖我更改的行,否则它不会起作用:

//nc.navigationBar.shadowImage = UIImage()
//nc.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "bar_background"), for: .default)

对于iOS13,定制导航栏的新方法是使用UINavigationBarAppearance

覆盖函数视图将出现(u动画:Bool){
超级。视图将显示(动画)
让navBarAppearance=UINavigationBarAppearance()
navBarAppearance.backgroundColor=.white
//或navBarAppearance.configureWithTransparentBackground()
navigationController?.navigationBar.standardAppearance=navBarAppearance
}
覆盖函数视图将消失(u动画:Bool){
超级。视图将消失(动画)
让navBarAppearance=UINavigationBarAppearance()
navBarAppearance.configureWithDefaultBackground()
navigationController?.navigationBar.standardAppearance=navBarAppearance
}
注:

  • 如果您的视图包含 滚动视图,并在顶部滚动
  • .compactAppearance
    用于 风景中的iPhone
  • .standardpearance
    用于其他

对于iOS13,定制导航栏的新方法是使用UINavigationBarAppearance

覆盖函数视图将出现(u动画:Bool){
超级。视图将显示(动画)
让navBarAppearance=UINavigationBarAppearance()
navBarAppearance.backgroundColor=.white
//或navBarAppearance.configureWithTransparentBackground()
navigationController?.navigationBar.standardAppearance=navBarAppearance
}
覆盖函数视图将消失(u动画:Bool){
超级。视图将消失(动画)
让navBarAppearance=UINavigationBarAppearance()
navBarAppearance.configureWithDefaultBackground()
navigationController?.navigationBar.standardAppearance=navBarAppearance
}
注:

  • 如果您的视图包含 滚动视图,并在顶部滚动
  • .compactAppearance
    用于 风景中的iPhone
  • .standardpearance
    用于其他

似乎很有希望,但没有成功。还是灰色的。有什么想法吗?@user3606650,显示你正在使用的代码和屏幕图像。我使用了你建议的代码(复制和粘贴)。在app delegate中使用它,甚至在VC viewdide方法中也是如此。不行。我甚至尝试了一个白色图像,并试图将其设置为背景图像。即使这样也会产生灰色。尝试使用着色颜色和不透明度。它只是产生了一个灰色的酒吧总是。似乎有希望,但它没有工作。还是灰色的。有什么想法吗?@user3606650,显示你正在使用的代码和屏幕图像。我使用了你建议的代码(复制和粘贴)。在app delegate中使用它,甚至在VC viewdide方法中也是如此。不行。我甚至尝试了一个白色图像,并试图将其设置为背景图像。即使这样也会产生灰色。尝试使用着色颜色和不透明度。它总是产生一个灰色的条。