iOS Autolayout如何水平拉伸(stretch)2个按钮

标签 ios autolayout

我需要从以下位置水平拉伸(stretch)所有按钮:

[button1][button2]

到:
[  button1  ][  button2  ]

取决于屏幕的宽度。

因此,我将 button1 固定到 superview 的顶部和左侧边缘。然后我将按钮 2 水平固定到按钮 1,并将按钮 1 的高度设置为相等,并将按钮 2 固定到右边缘。

这是我现在的问题:

enter image description here

最佳答案

你可以这样做:

左键的水平约束:
1.left button的领先等于superview的领先。
2.左键的拖尾等于superview的centerX(见下图)。

右键的水平约束:
1. 右键的领先等于左键的拖尾。
2.右键拖尾等于superview拖尾。

注意:根据您的需要放置垂直约束。

这是一个示例屏幕截图:

View Layout

Constraints

Left Button Constraint

关于iOS Autolayout如何水平拉伸(stretch)2个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27593170/

相关文章:

objective-c - iOS - 如何以编程方式设置 UISwitch

objective-c - NSLayoutConstraint.constraintsWithVisualFormat 右下对齐

ios - 自动布局 iOS 11 工具栏 UIBarButtonItem 与 customView

ios - 带有图片和文字的UIButton不起作用

ios - 如何关闭 Storyboard 弹出框

ios - ViewController 中的多个 UICollectionViews |不会调用一个 CollectionViews 委托(delegate)方法

ios - 可以忽略 Xcode 中冲突的约束吗?

iphone - 尝试使用 EventKit 时获取 "Undefined symbols"?

ios - 获取顶部约束的引用

ios - Animate Controls 因 UINavigationBar 的更改而下降