简体   繁体   English

iOS应用程序自动调整内容大小以适合不同的屏幕尺寸

[英]IOS Application automatic resize content to fit different screen size

I'm going to implement an ios application design. 我将实现ios应用程序设计。 The design is made with iphone 5 screen size in mind (640 x 1136 px). 设计时考虑了iPhone 5屏幕尺寸(640 x 1136 px)。

I want to automatically resize all the content to fit screen size of the display it will be running on, including: font size, bitmap size, subview size. 我想自动调整所有内容的大小以适合将在其上运行的显示器的屏幕大小,包括:字体大小,位图大小,子视图大小。

Ideally I want to code only once that assume the width of the device is 320 points regardless the actual width of the device. 理想情况下,我只想假设设备的宽度为320点,而无论设备的实际宽度如何,都只需编写一次代码。 Iphone 6 and 6s have bigger displays but still have the same aspect ratio. Iphone 6和6s具有更大的显示屏,但长宽比仍然相同。

For example if I create a box of UIView in my viewcontroller: 例如,如果我在viewcontroller中创建一个UIView框:

UIView *box = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
box.backgroundColor = [UIColor redColor];
[self.view addSubView:box];

will always draw a red box spanning full width of the screen regardless device screen size (in iphone 6 & 6s). 无论设备的屏幕尺寸如何(在iPhone 6和6S中),它将始终在屏幕的整个宽度上绘制一个红色框。 I do most of the visual component and layouting using code like above including for creating UILabel, etc. 我使用上述代码(包括用于创建UILabel等)来执行大多数视觉组件和布局。

Basically it is functioning like 'display zoom' feature in iphone 6, 6plus, but only for this application. 基本上,它的功能类似于iPhone 6、6plus中的“显示缩放”功能,但仅适用于此应用程序。 (not globally) (不在全球范围内)

What trick to do to get the desired result ? 要获得期望的结果该怎么做? If possible I don't want to use autolayout. 如果可能的话,我不想使用自动版式。

Thanks, 谢谢,

@night_coder, i am not sure about what ur trying to say, but based up on my understand i am answering you. @night_coder,我不确定您要说什么,但根据我的理解,我正在回答您。

You can go for Visual Layouts (If you trying programatically) 您可以使用视觉版式(如果您以编程方式尝试)

or 要么

you can go Auto Resizing, by disabling auto layouts and subviews (If you trying threw story board) 您可以通过禁用自动布局和子视图来进行自动调整大小(如果您尝试将情节提要投掷到故事板上)

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

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