自定义导航栏图像6

问题描述:

我试着去适应我的应用程序的iPhone 6自定义导航栏图像6

一切都是之前的工作以及时设置的自定义背景图片到我的导航栏:

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

由于这张图片是为iphone 4/5制作的,宽度不够。

你知道我可以为iPhone6设置正确的图像吗?

我试图命名我的图像[email protected][email protected],但它不会改变任何东西。

有什么想法?

更新: 我已经加入我用的是图像:

enter image description here

+0

iPhone 6不使用'@ 3x'图形,因为像素密度与iPhone 5相同并且下降。只有iPhone 6 Plus才会使用'@ 3x'图像。我怀疑问题在于图像的“伸展”? – dbart 2014-10-05 14:53:17

+0

感谢您的回答。不完全是,图像正在重复。 – Vico 2014-10-05 14:54:56

+0

最好的解决方案是采用“可拉伸”图像。在这种情况下,您可以为所有屏幕尺寸使用单个图像。你的导航栏图像是什么样的?你能发布一个屏幕截图吗? – dbart 2014-10-05 14:57:38

你应该创建一个可调整大小的图像,并将其设置为backgroundImage。根据提供的图像,您的左帽插图是82.0f分。您可以根据需要调整以适应文本。

另外,不要忘记,@3x图像仅在iPhone 6 Plus上使用,的iPhone 6

UIImage *backgroundImage  = [UIImage imageNamed:@"your-image-name"]; 
UIImage *resizableBackground = [backgroundImage resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 82.0f, 0.0f, 0.0f)]; 
[self.navigationController.navigationBar setBackgroundImage:resizableBackground forBarMetrics:UIBarMetricsDefault]; 
+0

非常感谢! :-) – Vico 2014-10-06 08:27:18

愿这也有帮助,它的做工精细(如果你的图像或阴影不同的),你可以用这一个也不过不同的图像,你必须设置为每个设备的规模:

NSLog(@"width is :%f",[[UIScreen mainScreen] bounds].size.width); 

UIImage *navBarImage =nil; 
if ([[UIScreen mainScreen] bounds].size.width==375.0f) { 
    navBarImage = [[UIImage imageNamed: @"[email protected]"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
} 
else if ([[UIScreen mainScreen] bounds].size.width==414.0f) { 
    navBarImage = [[UIImage imageNamed: @"[email protected]"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
} 
else{ 
    navBarImage = [[UIImage imageNamed: @"header-topbg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 

} 

[[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault]; 

你可以看到下面的图片为iphone6 +: enter image description here 谢谢。