简体   繁体   English

如何处理iPhone 4s,5和6屏幕尺寸,并使所有内容在设备上看起来相同

[英]How to handle iPhone 4s, 5 and 6 screen size, and make all the contents look the same across al the devices

I am using Xcode 6.1 and in one of the views I have, contains many labels. 我正在使用Xcode 6.1,在我的一个视图中,包含许多标签。 However, these labels look different in each different devices. 但是,这些标签在每个不同的设备中看起来不同。 Although I have add constraints to all the labels, but still facing the same issue. 虽然我已经为所有标签添加了约束,但仍面临同样的问题。

How can I get the same view layout across all devices? 如何在所有设备上获得相同的视图布局? How can I make the width and height for each label is flexible, depends on the screen size? 如何使每个标签的宽度和高度灵活,取决于屏幕尺寸? Do I need to design different xib for each device? 我是否需要为每个设备设计不同的xib?

The following images showing the result am getting, with auto resize enabled, and constants been added. 以下图像显示了结果,启用了自动调整大小,并添加了常量。

on iPhone 6 在iPhone 6上 在此输入图像描述

on iPhone 5 在iPhone 5上

在此输入图像描述

on iPhone iOS 7.1 在iPhone iOS 7.1上 在此输入图像描述

We have provided with a simple solution . 我们提供了一个简单的解决方案。 Using Aspect ratio constraint we can get a relative look in all device screens. 使用宽高比约束,我们可以在所有设备屏幕中获得相对外观。

I had the same issue and I found this >> http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/ 我有同样的问题,我发现了这个>> http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/

So when designing for lowest to highest screen resolution we can't set a specific width and height for all controls as it may look weird. 因此,在设计从最低到最高的屏幕分辨率时,我们无法为所有控件设置特定的宽度和高度,因为它可能看起来很奇怪。 So using this constraint we can have a relative look for all screens. 因此,使用此约束,我们可以对所有屏幕进行相对查看。

If you don't want to use constraints or you want to keep the same width & height , you can add scrollview to hold all controls. 如果您不想使用约束或想要保持相同的宽度和高度,可以添加scrollview来保存所有控件。 For that you can set a resizing frame for scrollview with fixed content size . 为此,您可以为具有固定内容大小的scrollview设置调整大小框架。

To solve this... 解决这个问题......

1) Go to xib file and uncheck the Auto layout 1)转到xib文件并取消选中“自动”布局

在此输入图像描述

2) Then set the autosizing manually in the following manner for each and every subview. 2)然后以下列方式为每个子视图手动设置自动调整大小。

在此输入图像描述

使用self.view.bounds.size.width获取屏幕宽度,然后使用相对值初始化所有标签。

一个灵魂是你可以为每个屏幕大小设计一个故事板,如iphone 5,一个用于iphone 6和一个用于iphone 6+,在你的AppDelegate方法“didFinishLaunchingWithOptions”你可以获得屏幕大小和弹出相应的故事板你可以根据不同的屏幕尺寸设置不同的约束

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

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