简体   繁体   English

如何让Xcode知道要用于目标iPhone的资产?

[英]How to let Xcode know which asset to use for the target iPhone?

I am designing an app for iOS in SWIFT . 我正在SWIFT中iOS设计一个应用程序。 I have decided that the auto layout will be compact and will be only for iPhone in portrait mode . 我已经决定自动布局将变得紧凑,并且仅适用于纵向模式下的iPhone I wanted to clear up a few hiccups on designing buttons for the 2 different screen ratios : the first being the iPhone 4s and the second ratio being the iPhone 5 and above . 我想为两种不同的屏幕比例设计按钮时遇到一些麻烦:第一个是iPhone 4s第二个是iPhone 5及更高版本 Because the new iPhones have a taller height, does that mean I will need to design 2 different ratios of buttons , and if so, how do I use them in Xcode? 因为新iPhone的高度更高,这是否意味着我将需要设计2种不同比例的按钮 ,如果是这样, 如何在Xcode中使用它们? For example here's the stock apple calculator; 例如,这是股票苹果计算器;

link to picture: http://imgur.com/mkIBghD 图片链接: http : //imgur.com/mkIBghD

As you can see the the buttons on the taller iPhone have a square shape. 如您所见, 较高的iPhone上按钮为方形。 The buttons on the 4s are more stubby . 4s上的按钮更粗略 What do I need to do in Xcode to let the app know which asset to use for the respective phone and how would I implement that in Auto Layout? 我需要在Xcode中做什么以使应用知道用于相应手机的资产,以及如何在自动版式中实现该资产 thanks 谢谢

In order to do this you setup autolayout constraints. 为此,您可以设置自动布局约束。 This will make the buttons change shape/size depending on the device. 这将使按钮根据设备而改变形状/大小。 You do not need to have multiple assets because all the phones you are talking about have the same retina (2x) display. 您不需要拥有多个资产,因为您正在谈论的所有电话都具有相同的视网膜(2x)显示屏。

You need to add three different sized images for a single Image Set in Images.xcassets . 您需要为Images.xcassets中的单个图像集添加三个不同大小的图像。 The sizes should be 1x for iPhone 4s, 2x for iPhone 6(It'll work for iPhone 5 too) and 3x for iPhone 6 plus. 对于iPhone 4s,尺寸应为1x;对于iPhone 6,尺寸应为2x(同样适用于iPhone 5);对于iPhone 6 plus,尺寸应为3x。 这是一个示例,看起来像

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

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