- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:label1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:label2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:5];
我试图在 VFL 中编写这段代码,但 VFL 似乎只提供了 NSLayoutFormatAlignAllTop 属性。所以我不能设置label1低于label2 5个点。
我想知道这个约束是否不能用VFL写。
最佳答案
你可以这样做,
NSArray *verticalConstraints1 =[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[label1]-20-|" options:0 metrics:nil views:views]; // this set top and bottom vertical constraint
NSArray *verticalConstraints1 =[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[label1]" options:0 metrics:nil views:views]; // this will set only top
NSArray *horizontalConstraints =[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[label1]-20-[label2]-20-|" options:0 metrics:nil views:views]; //this will vertical constraint between two label and top and bottom to label1 and label2 respactively
可以引用this link了解更多详情。
更新:
例如,
|-[button1(button2)]-[button2]-|
此约束意味着,button1 必须与 button2 的宽度相同,它们之间有一个标准间距,button1 是距 superview 左边缘的标准间距,button2 是距 superview 右边缘的标准间距.
如果你在这里使用 button1(button2/2)
那么这意味着它是 button2 的一半宽度。如果您需要这种高度方式的场景,那么只需在语句之前添加 V:
。
另一个例子,
V:|-(==padding)-[imageView]->=0-[button]-(==padding)-|
这个约束意味着,
ImageView 的顶部必须是距顶部的填充点 super View
ImageView 底部必须大于等于0从按钮顶部开始点
按钮的底部必须是从底部开始的填充点 super View 。
|[button(==200@750)]-[label]|
这个约束意味着,按钮的宽度应该是 200 点,优先级是 750。
|-30.0@200-[label]
标签应与父 View 左侧间隔 30 点,优先级为 200。
简而言之,您可以在 VFL
格式中设置任何类型的约束。
引用this link as reference了解更多详情!
希望这会有所帮助:)
关于ios - 如何将约束转换为 VFL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37453882/
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:label1 attribute:NSLayoutAtt
我想制作两个对齐到左边缘和右边缘的按钮,但是跟随 VFL 失败。 @"H:|[leftToolbar(60)]-[rightToolbar(60)]|" 结果好像都往左推了,右边第二个toolbar没
我正在尝试学习视觉格式语言,在这种情况下,我希望在 View 顶部有两个彼此相邻的按钮。 这是我的代码,但没有出现? UIButton *button1 = [[UIButton alloc] ini
我想知道是否有可能获得一个指向通过使用可视格式语言创建的约束的指针。 举个简单的例子,假设我已经为一个 View 创建了一个约束数组,它固定在它的 super View 的顶部、左侧和底部,但宽度为
我有一个自定义单元格,其中有一个 UILabel、UIButton 和 UIImageView。 您可以看到在第三行右侧(按钮控件 - selectionButton)收缩,因为按钮标题太长而无法容纳
AutoLayoutbyExample via Apple Developer Documentation 有人有示例说明如何创建间隔 View 以在 VFL 中设置标签之间的间距相等吗? label
我需要将标签和图像放入 TableView 单元格中,以便图像应紧邻标签放置,但在单元格可见范围内。即,它们应该如下所示, 当文本较小或在一行内时,图像可能紧邻标签。例如- Smaller text
我手动将 subview 添加到 View 并使用约束对其进行定位... UIView *superview = self.view; UIView *subview = self.subview;
我正在学习自动布局,我想设置一组垂直堆叠且间隔均匀的按钮。我还希望按钮固定在 View 底部。使用 VFL 设置这些约束的好方法是什么?按钮列表将作为 UIButton 数组传入。 NSArray *
我有以下代码,我正在尝试实现添加到垂直 ScrollView 的动态图像。我想要它的约束,以便图像将自身设置在 ScrollView 的边界内。 但是结果是图像似乎保持其原始大小(比 ScrollVi
当我尝试根据设备方向在单个 View Controller 中动态分配约束时,我遇到了意外的行为。 期望的行为:如下面的代码所示,我使用 VFL 将 View 附加到 super View 的右边缘、
我已经使用自动布局在 Storyboard中设计了我的 View ,但是我在使用 VFL 以编程方式实现它时遇到了一些问题。这个 View 在纵向上看起来像这样 三个 subview 按某种顺序垂直布
我是 iOS 开发的新手,VFL 让我很头疼。我正在尝试将以下约束转换为 VFL 以作为研究案例的简单 View ,但我的宽度从未被推断出来,除非我明确指定宽度,否则 View 永远不会显示。 H:|
我在 iOS 8 上的 VFL 中遇到了约束问题,而在 6 和 7 上一切正常。这是约束条件: H:|-margin-[_imageView]-(=>margin)-[_label]-margin-|
我正在了解 VFL,并且正在尝试一些我需要帮助的东西。 我在纵向模式下将 ImageView 对齐,如下图所示。 横向 View 如下所示 在横向中,我希望图像沿 Y 轴居中,即比图像中显示的稍高一些
|我的 View Controller 中有一个带有自定义 UITableViewCell (单元格)的 TableView (alertTableView)。对于这个 UITableViewCell
我正在开发的应用程序有很多视觉格式的限制。在一次操作中集中一些网络请求后,我开始遇到 EXC_BAD_ACCESS 崩溃。如果我通过 NSLayoutConstraint(item....) 初始值设
我正在使用使用视觉格式语言的自动布局。 在水平模式下,我可以像这样在一行代码中包含两个标签 constraints = [NSLayoutConstraint constraintsWithVis
我正在学习通过代码在 VFL 中编写约束 我的 View 水平居中: let constraintY = NSLayoutConstraint.constraintsWithVisualFormat(
所以我正在做一些非常简单的事情,我想让一个对象与其父 View 的边缘底部保持固定的距离。说20个ios点。我尝试以下操作: addConstraintsWithFormat("V:|[v0]-2
我是一名优秀的程序员,十分优秀!