目标 C:如何保持导航按钮和选项卡栏中的图像分辨率/质量

发布于 2024-11-25 18:14:26 字数 803 浏览 2 评论 0原文

我试图通过以下代码将图像放置到导航项的右侧按钮

//Add image to right bar button in navigation bar
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"refresh.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(getData)];

self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];

图像我的尺寸为 52 X 52 像素。 如果我只是将图像添加到按钮而不更改大小,我将得到不成比例的显示,如下所示

在此处输入图像描述

但是,如果我在添加到按钮之前尝试缩小图像(18 X 18 像素),则图像在 iPhone 视网膜显示屏上看起来会很模糊

在此处输入图像描述

iPhone 视网膜显示屏的标签栏也会发生这种情况。

在此处输入图像描述

有没有办法在按钮或选项卡中使用大图像而不会出现不成比例的显示?或者有没有办法保持图像的分辨率?

I am trying to put an image to the navigation item's right button via the following code

//Add image to right bar button in navigation bar
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"refresh.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(getData)];

self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];

The image I has a dimension of 52 X 52 pixels.
If I just add the image into the button without changing the size, I will get a unproportionate display as seen below

enter image description here

However, if I try to shrink the image before adding to the button (18 X 18 pixels), the image will look blurry on the iPhone retina display

enter image description here

This is also happening for the tab bars for the iPhone retina display.

enter image description here

Is there any way to use a large image in the button or tab without getting a disproportionate display? Or is there a way to maintain the resolution of the image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执着的年纪 2024-12-02 18:14:26

您需要创建两个图形资源,一个为正常大小,另一个为视网膜加倍,并在文件名中添加@2x。您可以阅读更多信息:

https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreensInViews/SupportingHiResScreensInViews.html#//apple_ref/doc/uid/TP40010156-CH15-SW1

You need to create two graphic assets, one in normal size other doubled for retina with @2x added to filename. You can read more at:

https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreensInViews/SupportingHiResScreensInViews.html#//apple_ref/doc/uid/TP40010156-CH15-SW1

心作怪 2024-12-02 18:14:26

在界面生成器中查看图像的边缘插入。您可以调整左右值来调整 UIButton 中更大图像的大小。

Ib Frame

UIbutton 的等效属性是 [uiButton setImageEdgeInsets:<#(UIEdgeInsets)#>]

Check out the Edge Insets for image in the interface builder. You can adjust the left right values to resize a bigger image in a UIButton.

Ib Frame

Equivalent property of UIbutton is [uiButton setImageEdgeInsets:<#(UIEdgeInsets)#>]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文