objective-c - Objective-C : How to maintain image resolution/quality in navigation buttons and tab bars

标签 objective-c ios uiimage resolution

我正在尝试通过以下代码将图像放在导航项的右侧按钮上

//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];

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

enter image description here

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

enter image description here

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

enter image description here

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

最佳答案

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

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

关于objective-c - Objective-C : How to maintain image resolution/quality in navigation buttons and tab bars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6815010/

相关文章:

objective-c - 重新初始化 NSMutableArray 为 NSMutableArray

ios - 为什么页眉和页脚在删除时会跟随行的移动?

ios - UIImage 如何使用 capInsets 调整气泡图像的大小?

objective-c - 显示来自 json 的图像

ios - Yelp API ios 获取更大的图像

ios - arc4random() 效率中断?

objective-c - NSWindow 内存选项

iphone - iPhone 热图

ios - 容器 View 中的按钮在第二个 View 中不起作用

iOS - 授权访问