理解“firstBaseLine”与“baseLine”相对AutoLayout约束 [英] Understanding "firstBaseLine" vs. "baseLine" AutoLayout Constraint

查看:2172
本文介绍了理解“firstBaseLine”与“baseLine”相对AutoLayout约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下视图,如下所示:





并使用添加缺失约束 t自动添加约束。
我在iOS世界中相当新,我正在尝试配置约束如何工作。



在文档大纲中,我可以看到增加的约束:





我点击标签 UR 和尺寸检查员告诉我以下内容:




I've created the following view that looks as follow:

And used Add missing constraints t automatically add constraints. I am pretty new in iOS world and I'm trying to configure out how constraints work.

On document outline, I can see the added constraints:

I click on label UR and Size inspector show me following:

What is the difference between constraints aligned by first baseline to UL and aligned by baseline to UL? When I click on the size inspector on constraints button, it shows me the same line.

解决方案

From the Apple Docs:

NSLayoutAttributeBaseline
The object’s baseline.
Available in iOS 6.0 and later.

NSLayoutAttributeFirstBaseline
The object’s baseline. For objects with more than one line of text, this is the baseline for the topmost line of text.
Available in iOS 8.0 and later.

Here is also a screenshot of the difference when aligning to a three line label. The upper green label is using NSLayoutAttributeFirstBaseline and the lower green label is using NSLayoutAttributeBaseline. These are the only constraints on the two green labels besides they are both Horizontally pinned 40 from the Pink Label

这篇关于理解“firstBaseLine”与“baseLine”相对AutoLayout约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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