自动布局和放大器;对齐约束 [英] Autolayout & Alignment Constraints

查看:207
本文介绍了自动布局和放大器;对齐约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想做出类似的用户界面为所有iPhone和我目前使用的自动布局,但我不知道如何创建使用`NSLayoutConstraint`这个`UI`?

I want to make similar ui for all iPhones & i am currently using auto layout for that, but i do not know how to create this `UI` using `NSLayoutConstraint`?

这个UI作品在小画面精美,但我想相同的用户界面更大的iPhone以及(保持一定量的按钮之间的空间)。我怎么能在这加约束来得到相同的用户界面为iPhone 4S。

This UI works fine in small screen but i want same ui for bigger iPhone as well(keep certain amount of space between buttons). how can i add constraint in this to get same ui as iPhone 4s.


有人帮我在这里。

Some one help me out here.

截图。

推荐答案

我个人发现试图使自动布局约束感code(以及使用NSLayoutConstraint)是相当混乱,很难理解。 <一href=\"https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html\"相对=nofollow> VFL(可视化格式语言)是强大的,但我会建议,如果你是刚刚开始接触,然后自动布局故事板的工作或XIB文件可能会更容易(取决于你个人的preference)。

Personally I find that trying to make sense of Auto Layout constraints in code (and using NSLayoutConstraint) to be quite confusing and difficult to understand. VFL (Visual Format Language) is powerful but I would recommend if you are just starting out with Auto Layout then working in Storyboard or a XIB file may be easier (depends on your individual preference).

由于这是一个相当复杂的话题我已经把一个示例项目,为您在GitHub上引用。这种方法的好处是,有字面上没有code - 所有的配置在故事板完成(或者,也可以在一个XIB文件完成)。我创建的约束亮点低于但请注明出处的具体细节示例项目:

Since this is quite an involved topic I've put together a sample project for you to reference on GitHub. The benefit of this approach is that there is literally no code - all of the configuration is done in the Storyboard (or can also be done in a XIB file). Highlights of the constraints I created are below however please reference the sample project for specific details:


  • 背景视图(紫色) - 约束针的顶部,底部,左,右两侧给父视图的边缘

  • 图标集装箱视图(白色) - 约束针的底部,左侧和右侧;高度也设置容纳所有的图标。

  • 所有图像视图的宽度约束和纵横比约束(保持相等的宽度和高度)和所有标签被限制到相应的图像与相应的垂直约束(顶部)。

  • 的外角图标都仅仅限于他们的角(左上,右上,左下,右下)。该中心的角落被限制要在视图中水平居中。

如果你是刚开始使用自动布局你会发现的以下presentation我做在学习基础知识很有帮助。

If you are just getting started with Auto Layout you may find the following presentation I made helpful in learning the basics.

下面是来自不同的模拟器了三个截图,显示了如何布局自动调整取决于屏幕尺寸:iPhone 5S,iPhone 6,和iPhone 6加:

Here are three screenshots from different simulators which show how the layout adjusts automatically depending on the screen size: iPhone 5s, iPhone 6, and iPhone 6 Plus:

从技术上讲,横向也被这些约束支持,但结果可能会或可能不适合您的要求。 (我不确定什么方向你计划的支持。)

Technically, landscape orientation is also supported by these constraints however the result may or may not fit your requirements. (I am unsure what orientations you are planning to support.)

这篇关于自动布局和放大器;对齐约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆