UINavigationBar的自定义样式无法正常工作 [英] Custom styling of UINavigationBar not working properly

查看:101
本文介绍了UINavigationBar的自定义样式无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码为所有UINavigationBars设置自定义背景图像.问题在于最终图像似乎不是视网膜大小.我研究了UINavigationBars是640x88px.那就是我的UINavigationBar.png的确切尺寸,但是我在iPhone Sim(视网膜)和我的iPhone 4(也是视网膜)上只能看到320x44px.

I am using this code to set custom background image for all UINavigationBars. The problem is that the final image does not appear to be retina size. I researched UINavigationBars are 640x88px. Thats exact dimensions of my UINavigationBar.png however I only see 320x44px on the iPhone Sim(retina) and my iphone 4 which is also retina.

设置图像的代码:

UIImage *background = [UIImage imageNamed:@"UINavigationBar.png"];
[[UINavigationBar appearance] setBackgroundImage:background forBarMetrics:UIBarMetricsDefault];

以下是用于说明的屏幕截图:

Here is a screenshot for illustration:

(区别是没有在Photoshop中出现底部暗线.在iPhone 5 Simulator(视网膜)中我只能看到一半的图像)

(the difference is there is no bottom dark line as in Photoshop. I can only see half of the image in the iPhone 5 Simulator (Retina))

我的问题是为什么会发生这种情况,我该如何解决?谢谢.

My question is why this happens and how can I fix it? Thanks.

推荐答案

您需要具有两个大小和名称相同的.png文件,但在视网膜显示文件中添加@ 2x.
例如

You need to have two .png files with different size and same name, but with @2x addition in the retina display file.
For example,

用于常规显示支持的文件1:
尺寸-320x44,
名称-UINavigationBar.png

File 1 for regular display support:
size- 320x44,
name- UINavigationBar.png

支持视网膜显示的文件2:
尺寸-640x88,
名称-UINavigationBar@2x.png

File 2 for retina display support:
size- 640x88,
name- UINavigationBar@2x.png

在您的代码中,您始终使用UINavigationBar.png,根据硬件,设备将自动知道要使用的巫婆文件.

In your code you always use UINavigationBar.png, the device will automatically know witch file to use, according to the hardware.

这篇关于UINavigationBar的自定义样式无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆