简体   繁体   English

适用于不同iPhone的iOS图像尺寸指南

[英]Ios image size guide for different iphones

I am just confused about the image sizes that I need to use for buttons, image views etc. I want to adjust images for all iphones. 我只是对需要用于按钮,图像视图等的图像大小感到困惑。我想为所有iPhone调整图像。 What should be ratio between the screen height/width and different iphones. 屏幕高度/宽度与不同iPhone之间的比例应为多少。

Like i have a button. 就像我有一个按钮。 I have created in following way- 我以以下方式创建-

 UIButton *takePicButton = [UIButton buttonWithType:UIButtonTypeCustom];
takePicButton.frame = CGRectMake(0, SCREEN_HEIGHT-UI_ITEM_HEIGHT, SCREEN_WIDTH, UI_ITEM_HEIGHT);
[takePicButton setBackgroundImage:[UIImage imageNamed:@"take_photo.png"] forState:UIControlStateNormal];
[self.view addSubview:takePicButton];
[takePicButton addTarget:self action:@selector(takePicture:) forControlEvents:UIControlEventTouchUpInside];

for this button what size of images I need to add on xcode to support iPhone 4 - iPhone 7. 对于此按钮,我需要在xcode上添加多少尺寸的图像以支持iPhone 4-iPhone 7。

Thanks in advance. 提前致谢。

Here is description about how image can set in iPhone: 这是有关如何在iPhone中设置图像的说明:

•   1x images are for the original iPhone through the 3GS - 'standard' resolution devices (3.5" screens)


•   2x images are for the iPhone 4 and 4S (3.5" Retina screens) and are also used for the iPhone 5, 5s,6,6s,7

•   3x images are for the new iPhone 6+,7+ (5.5" super-Retina [3x] screen)


You have to keep three different types of image into your Assets.xcassets and just provide image name at where you want to display it. 您必须将三种不同类型的图像保留在Assets.xcassets中,并仅在要显示图像的位置提供图像名称。 It will automatically take relevant image and display it. 它将自动拍摄相关图像并显示。

You can check attached screenshots. 您可以查看随附的屏幕截图。 You just have to write “bgImag” and it will take relevant image from assist. 您只需要编写“ bgImag”,它将从协助中获取相关图像。 在此处输入图片说明 About image ration, just create image for highest resolution of iPhone (ie iPhone 6+), and just use iConify to get rest of image assest. 关于图像定量,只需创建分辨率最高的iPhone (即iPhone 6+)图像,然后使用iConify即可获取其余图像。

Try this, u can ask for two sizes. 试试这个,你可以要求两种尺寸。 One is SCREEN_WIDTH * 2, UI_ITEM_HEIGHT * 2, the other is SCREEN_WIDTH * 3, UI_ITEM_HEIGHT * 3.Then put two sizes pics in your Images.xcassets named xxx@2x, xxx@3x. 一个是SCREEN_WIDTH * 2,UI_ITEM_HEIGHT * 2,另一个是SCREEN_WIDTH * 3,UI_ITEM_HEIGHT * 3,然后在您的Images.xcasset中放入两个尺寸为xxx @ 2x,xxx @ 3x的图片。

You should simply use: 您应该简单地使用:

UIImage *imButton = [UIImage imageNamed:@"image.png"];

[YOURBUTTON setImage:imButton forState:UIControlStateNormal];

Xcode will automatically use the available image with scales ex: @2x or @3x Xcode将自动使用可用图像,缩放比例为: @2x@3x

From my example your images would be: 从我的示例中,您的图像将是:

image.png (20x20 px), image.png (20x20 px),
image@2x.png , (40x40 px) image@2x.png ,(40x40 px)
image@3x.png , (60x60 px) image@3x.png ,(60x60 px)

respectively. 分别。

Quoting from apple: 从苹果报价:

Image Size and Resolution 图像尺寸和分辨率

iOS uses a coordinate system to place content onscreen. iOS使用坐标系将内容放置在屏幕上。 This coordinate system is based on measurements in points, which map to pixels in the display. 该坐标系基于点的测量,这些点映射到显示器中的像素。 On a standard-resolution screen, one point (1/72 of an inch) is equal to one pixel. 在标准分辨率的屏幕上,一个点(1/72英寸)等于一个像素。 High-resolution screens have a higher pixel density. 高分辨率屏幕具有更高的像素密度。 Because there are more pixels in the same amount of physical space, there are more pixels per point. 因为在相同数量的物理空间中有更多像素,所以每个点有更多像素。 As a result, high-resolution displays require images with more pixels. 结果,高分辨率显示器需要具有更多像素的图像。

Refer here 请参考这里

I want to adjust images for all iPhones. 我想为所有iPhone调整图像。

The easy way to do that is to use layout constraints. 最简单的方法是使用布局约束。 Your code tries to do what the constraints system would, given an appropriate set of constraints, but it's less flexible because it doesn't provide for changing geometry such as when the user rotates the device. 给定一组适当的约束,您的代码会尝试执行约束系统将要执行的操作,但是它的灵活性较差,因为它不提供更改几何形状的功能,例如用户旋转设备时。

What should be ratio between the screen height/width and different iphones[?] 屏幕高度/宽度与不同iphone之间的比例应该是多少?

Different devices have different aspect ratios. 不同的设备具有不同的纵横比。 There are lots of web sites (like this one ) that list the screen sizes. 有许多列出屏幕尺寸的网站(像这样的网站)。 When possible, though, it's best not to make any assumptions about screen size. 不过,如果可能的话,最好不要对屏幕尺寸做任何假设。 New devices may be introduced with different aspect ratios, and even a single device may appear to have different screen sizes depending on how the user chooses to use it -- things like rotation and split screen affect the size and shape of the screen real estate that your device gets to use. 可能会以不同的宽高比引入新设备,甚至单个设备也可能会显示出不同的屏幕尺寸,具体取决于用户选择使用它的方式-诸如旋转和拆分屏幕之类的因素会影响屏幕空间的大小和形状,您的设备开始使用。

for this button what size of images I need to add on xcode to support iPhone 4 - iPhone 7[?] 对于此按钮,我需要在xcode上添加多少尺寸的图像以支持iPhone 4-iPhone 7 [?]

We can't say without knowing what your UI_ITEM_HEIGHT constant is or what relative proportions you want for your button, but you should be able to calculate that yourself if you know the various screen sizes. 我们不能不知道您的UI_ITEM_HEIGHT常量是多少,还是想要按钮的相对比例而说,但是如果您知道各种屏幕尺寸,就应该能够自己计算出该比例。 You can use the reference I linked above, or this one , or one of the many others out there. 你可以用我上面链接引用,或这一个 ,或许多其他的一个在那里。

Guys You can try below code: 伙计们,您可以尝试下面的代码:

 if (IS_IPHONE4) {
        imgHeight.constant = 150;
    }
    else if (IS_IPAD) {
        imgHeight.constant = 300;
    }
    else if (IS_IPHONE5) {
        imgHeight.constant = 170;
    }
    else {
        imgHeight.constant = 200;
    } 

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM