2013-03-08 138 views
2

所以我尝试在MonoTouch中为导航栏设置背景图像。图像在任何地方都是一样的。我将如何做到这一点?设置背景图像导航栏

在viewdid负载:NavBar.SetBackgroundImage(UIImage.FromFile ("btn-title-bar.png"));

不起作用。

回答

3

尝试

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"btn-title-bar.png"] forBarMetrics:UIBarMetricsDefault]; 
+0

+1不错的答案。 – Dilip 2013-03-08 12:47:50

+1

是的,这工作!在c#中它将是:gettingStartedBar.SetBackgroundImage(UIImage.FromBundle(“top-bar.png”),UIBarMetrics.Default); – 2013-03-08 12:52:44

2

在C#中的土地即:

UINavigationBar.Appearance.SetBackgroundImage (UIImage.FromFile ("btn-title-bar.png"), UIBarMetrics.Default); 
+0

错误CS1501:方法'SetBackgroundImage'没有重载需要'1'参数(CS1501) – 2013-03-08 12:41:23

+0

道歉没有检查添加。 – Blounty 2013-03-08 19:15:21

0
如果你想要把不同的图像的每一页上则写这个方法

鉴于所做的每一页上加载..

UIImage *image = [UIImage imageNamed: @"logo.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage: image]; 
self.navigationItem.titleView = imageView; 

如果你想在每个页面上显示单个图像,那么把这段代码写在delegate.m中。

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"logo.png"] 

forBarMetrics:UIBarMetricsDefault]; 
1

试试下面的代码。

UIImage *image = [UIImage imageNamed: @"[email protected]"]; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage: image]; 
    imageView.frame = CGRectMake(0, 0, 320, 44); 
    [self.navigationController.navigationBar addSubview:imageView];