`
lizhuang
  • 浏览: 889213 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Auto Layout三种形态

阅读更多
Auto Layout builds constraints in three ways. So far, you’ve read about two of them. First, you can lay out your constraints in Interface Builder(IB) and customize them to your needs.Second, you can build single constraints in code. The NSLayoutConstraint class offers the constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant: method, which enables you to create constraints one at a time, relating one item’s attribute to another. In this chapter, you’ll read about the third way: using a visual formatting language to express how items are laid out along vertical and horizontal axes.

This chapter explores what these visual constraints look like, how you build them, and how you use them in your projects. You’ll read about how metrics dictionaries and constraint options extend visual formats for more flexibility. And you’ll see numerous examples that demonstrate these formats and explore the results they create.

There’s one thing to keep in mind throughout: All constraints are members of the NSLayoutConstraint class, regardless of how you build them. Every constraint stores a “y relation mx +b” rule within an Objective-C object and expresses that rule through the Auto Layout engine. Visual formats are another tool that takes you to that same place.

使用IB,代码写的NSLayoutConstraint,还有Visual formats转化的NSLayoutConstraint.


Layout constraints (NSLayoutConstraint class, public)

These rules specify view geometry. They restrict a view’s position and size by relating a view to other views and / or to constant values.

Content size constraints(NSContentSizeLayoutConstraint class, private)

Content size rules specify how a view’s size should relate to its content. For example, content hugging rules avoid adding padding, and content compression rules prevent clipping.

Autosizing constraints (NSAutoresizingMaskLayoutConstraint class, private)

Autosizing constraints translate the older autosizing masks into the Auto Layout system.

Layout support constraints (_UILayoutSupportConstraint class, private)

Introduced in iOS7, layout support constraints establish practical boundaries for the tops and bottoms of your view controller instances. These constraints restrict content from overlapping with obstacles such as status bars.


Prototyping constraints (NSIBPrototypingLayoutConstraint class, private)

Also new to iOS 7, prototyping constraints are constraints that Interface Builder(IB) adds for you. They enable you to build interfaces incrementally yet still have a working interface to test. When you ship apps, your code should not use, reference, or otherwise include prototyping constraints.


In IB, you create layout support constraints by constraining views to top or bottom layout guide proxies.

UIView *topLayoutGuide = (UIView *)self.topLayoutGuide;
CONSTRAIN(@”V:[topLayoutGuide][textView]|”, topLayoutGuie, textView);

In this example, a text view stretches between the top guide, which defines the top of the application context space, and the bottom of the parent.
分享到:
评论

相关推荐

    autocad命令全集

    17 ACISOUT   将AutoCAD三维实体目标输出到ACIS文件 18 ADCCLOSE   关闭AutoCAD设计中心 19 ADCENTER ADC 启动AutoCAD设计中心 20 ADCNAVIGATE ADC 启动设计中心并访问用户设置的文件名、路径或网上目录 21 ALIGN ...

    EPS R17.32-2012.06(去除或添加AutoCAD教育版打印戳记).rar

    而对于之前已打开的每个文件,要使该状态有效地存入文件,都需在存盘之前,在AutoCAD中执行下列操作之一:打印、打印预览、粘贴CAD对象(从本文件或其它文件复制均可)、插入外部块、从模板插入Layout、插入外部参照...

    EPS R18.32-2012.06(去除或添加AutoCAD教育版打印戳记).rar

    而对于之前已打开的每个文件,要使该状态有效地存入文件,都需在存盘之前,在AutoCAD中执行下列操作之一:打印、打印预览、粘贴CAD对象(从本文件或其它文件复制均可)、插入外部块、从模板插入Layout、插入外部参照...

    EPS R16.32-2012.06(去除或添加AutoCAD教育版打印戳记).rar

    而对于之前已打开的每个文件,要使该状态有效地存入文件,都需在存盘之前,在AutoCAD中执行下列操作之一:打印、打印预览、粘贴CAD对象(从本文件或其它文件复制均可)、插入外部块、从模板插入Layout、插入外部参照...

    EPS R18.64-2012.06(去除或添加AutoCAD教育版打印戳记).rar

    而对于之前已打开的每个文件,要使该状态有效地存入文件,都需在存盘之前,在AutoCAD中执行下列操作之一:打印、打印预览、粘贴CAD对象(从本文件或其它文件复制均可)、插入外部块、从模板插入Layout、插入外部参照...

    LoadingLayoutDemo-加载中、无网络、无数据、出错4种状态的载入布局.zip

    前言项目里都会遇到几种页面,分别为加载中、无网络、无数据、出错四种情况,经常要使用,所以封成库引用了,方便使用,顺便分享出来。先看一下效果: 原理比较简单,继承FrameLayout,在xml渲染完成后,加上加载中...

    EasyPeasy:轻松实现自动布局

    EasyPeasy是一个Swift框架,可让您以编程方式创建Auto Layout约束而不会感到头疼,并且永远不会结束样板代码。 除了基础知识之外, EasyPeasy还可以为您解决大多数约束冲突,还可以将其附加到约束条件闭包上,这些...

    ProgressLayout-数据载入状态布局.zip

    数据载入状态布局集成allprojects {  repositories {  maven { url "https://jitpack.io" }  } }dependencies {  compile 'com.github.nguyenhoanglam:ProgressLayout:1.0.1' }使用像使用...

    LCRapidDevelop-master

    mQuickAdapter = new ListViewAdapter(R.layout.list_view_item_layout,null); //设置加载动画 mQuickAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN); //设置是否自动加载以及加载个数 mQuickAdapter....

    TinyConstraints:只是糖

    TinyConstraints是使Auto Layout更适合人类使用的语法糖。产品特点 纯粹的Swift 5甜度。 您可以使用“自动版式”进行所有操作,但是要简短一些。 约束默认情况下处于活动状态。 与其他自动版式代码100%兼容。 (可...

    multistatetogglebutton:Android的多状态切换按钮

    LinearLayout xmlns : android = " http://schemas.android.com/apk/res/android " xmlns : mstb = " http://schemas.android.com/apk/res-auto " android : layout_width = " match_parent " android : layo

    CircleIndicator-一个轻量级的viewpager指示器 ,类似于nexus5 启动器的效果.zip

    设置当前的小圆点恢复到未选中时的状态的动画。例如:当前正从a切换到b,那么该属性设置的是a的动画。ci_animator_reversereference和"ci_animator"属性一样,只不过该属性设置的是b的动画。ci_drawablereference...

    CadenceAllegro16.5培训教程.pptx

    PCB Layout流程 Interactive and automatic route signals HDL/schematic design capture Define board mechanical stackup Set/check CBD rules and constraints Load logic data Arrange/place components ...

    CAD快捷键文档

    在使用过程中,试着用命令的第一个字母,不行就用前两个字母,最多用前三个字母,也就是说,AutoCAD的快捷命令一般不会超过三个字母,如果一个命令用前三个字母都不行的话,只能输入完整的命令。 2、 另外一类的...

    SuperButton-这真的可能是最好用的按钮了.zip

    这本来没有什么问题,也比让UI妹纸切图高级了很多,但是随着开发的进行你会发现,UI妹纸的想法很多,不同的界面有各种不同圆角和不同背景颜色的按钮,这个时候你需要把上面的三个步骤再进行N次。最后你会发现你的...

    Android GridView 滑动条设置一直显示状态(推荐)

    模拟GridView控件: <GridView android:id=@+id/picture_grid android:layout_width=match_parent ... android:numColumns=auto_fit android:gravity=center android:verticalSpacing=8dp android:horizontal

    ListView 分页加载更新实例分享

    有图有真像: 列表初始状态 触发加载 加载后 部分代码: MainActivity 代码如下: private void initActivity() { // TODO Auto-generated method stub loadMoreView = getLayoutInflater().inflate(R.layout

    新版Android开发教程.rar

    � 由于采用了 Java 作为应用开发语言,目前可用的传统第三方应用还很少,但由于 Android 是一款完全 开 源的移动计算平台,相信第三方应用会很快的丰富起来。 � Google 提供了一套 Java 核心包 (J2SE 5,J2SE 6) 的...

    Ext Js权威指南(.zip.001

    9.4.10 自动布局:ext.layout.container.auto / 453 9.4.11 表格布局:ext.layout.container.table / 454 9.4.12 列布局:ext.layout.container.column / 455 9.4.13 自适应布局:ext.layout.container....

    纯C日志函数库zlog.zip

     * 日志格式定制,类似于log4j的pattern layout  * 多种输出,包括动态文件、静态文件、stdout、stderr、syslog、用户自定义输出函数  * 运行时手动或自动刷新配置(同时保证安全)  * 高性能,在我的...

Global site tag (gtag.js) - Google Analytics