Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Ios 如何在Objective-C中设置UINavigationBar的背景?_Ios_Objective C_Uinavigationbar - Fatal编程技术网

Ios 如何在Objective-C中设置UINavigationBar的背景?

Ios 如何在Objective-C中设置UINavigationBar的背景?,ios,objective-c,uinavigationbar,Ios,Objective C,Uinavigationbar,我正在尝试更改UINavigationBar的背景 我已经将图像放入Images.xcasets,并且xib文件是TableView 我已经为BarMetrics:UIBarMetricsDefault编写了[[UINavigationBar外观]setBackgroundImage:[UIImage ImageName:@“bar background.png”]加载,如下所示 - (void)viewDidLoad { [super viewDidLoad]

我正在尝试更改
UINavigationBar
背景

我已经将图像放入
Images.xcasets
,并且
xib
文件是
TableView

我已经为BarMetrics:UIBarMetricsDefault编写了
[[UINavigationBar外观]setBackgroundImage:[UIImage ImageName:@“bar background.png”]视图中的code>加载
,如下所示

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.

        UIView* bview = [[UIView alloc] init];
        bview.backgroundColor = [UIColor groupTableViewBackgroundColor];

        //self.title = NSLocalizedString(@"WiFi Camera Viewer", nil) ;
        [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bar-background.png"] forBarMetrics:UIBarMetricsDefault];
}
但是
UINavigationBar
没有显示任何如下图像

如何在Objective-C中设置UINavigationBar的背景?


我错过什么了吗?提前感谢。

您使用的代码很旧,从iOS 7开始,您可以使用以下代码

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"YourImage"] forBarMetrics:UIBarMetricsDefault];

如果您提供的图像高度为44px,它将仅覆盖导航栏而不覆盖状态栏;如果您提供的图像高度为66px,它将同时覆盖它们两个

您确定有名为“bar background.png”的图像吗?谢谢您的帮助!