ios UITabBarItem 图片大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18660139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UITabBarItem Image Size
提问by user2397282
I am making images for my UITabBar. I am making them of size 60x60, because that's what retina screens use. However, when I use that size, it shows up too big in the bar, so you can only see part of the image. When I reduce it down to 30x30, it works, but that size is supposed to be for non-retina displays. Why does it not show up properly when I use 60x60?
我正在为我的 UITabBar 制作图像。我正在制作 60x60 的尺寸,因为这是视网膜屏幕使用的。但是,当我使用该尺寸时,它在栏中显示太大,因此您只能看到图像的一部分。当我将其缩小到 30x30 时,它可以工作,但该尺寸应该用于非视网膜显示器。为什么当我使用 60x60 时它不能正确显示?
回答by thatzprem
You probably may have to rename your retina image to [email protected]
.
您可能需要将您的视网膜图像重命名为[email protected]
.
回答by radiovisual
You were getting this behavior because you were supplying a high-resolution image, when iOS was looking for a standard resolution image.
您之所以出现这种行为,是因为当 iOS 正在寻找标准分辨率图像时,您提供的是高分辨率图像。
iOS automatically selects the appropriate image size for you, depending on the resolution of the accessing device. So you will be responsible for supplying a "standard resolution" image, for non-retina devices, and a "high resolution" image, for retina displays. The way you do this in iOS is to append "@2x" to the end of your filename, but before the file extension, like this:
iOS 会自动为您选择合适的图像大小,具体取决于访问设备的分辨率。因此,您将负责为非视网膜设备提供“标准分辨率”图像,以及为视网膜显示器提供“高分辨率”图像。在 iOS 中执行此操作的方法是将“@2x”附加到文件名的末尾,但在文件扩展名之前,如下所示:
my-image.png // for non-retina displays (Ex: 30x30 dpi)
[email protected] // for retina displays (Ex: 60x60 dpi)
[email protected] // for retina displays(plus editions) (Ex: 90x90 dpi)
Then, when you are referencing files in your XCode project, you only need to supply the filename to the standard resolution (e.g, "my-image.png") and if the accessing device has a retina display, then XCode will automatically select the file with the "@2x" suffix for you.This is very convenient, because it saves us developers from having to detect whether or not the device has a retina display, and which image we need to supply.
然后,当你在你的 XCode 项目中引用文件时,你只需要提供标准分辨率的文件名(例如,“my-image.png”),如果访问设备有视网膜显示,那么XCode 将自动选择为您创建带有“@2x”后缀的文件。这非常方便,因为它使我们开发人员不必检测设备是否具有视网膜显示屏,以及我们需要提供哪些图像。
Here is a code example:
这是一个代码示例:
// Select an image named "my-image.png"
UIImage *img = [UIImage imageNamed:@"my-image.png"];
// If the device this code is run on is a retina device,
// then Xcode will automatically search for "[email protected]" and "[email protected]"
// otherwise, it will use "my-image.png"
You can read more on the subject via the Apple Developer's Site: Optimizing for High Resolution
您可以通过 Apple Developer's Site: Optimizing for High Resolution阅读有关该主题的更多信息