iOS Autolayout: two buttons of equal width, side by side(iOS自动布局:两个等宽的按钮,并排)
问题描述
我目前在使用 AutoLayout 时遇到困难.我正在使用界面生成器,并尝试将两个等宽的按钮并排放置,如下图所示.
I am currently having difficulty with AutoLayout. I am using interface builder and am trying to position two buttons of equal width side by side as illustrated in the following image.
从下面的预览图像中,我的 titleImage 已得到适当的约束并且可以正确显示,但按钮却没有.我已经尝试将按钮 1 与 titleImage 的前缘对齐,将 button2 与 titleImage 的后缘对齐,但是此时两个按钮之间的宽度分布变得倾斜,如下所示.
From the following Preview image, my titleImage has been properly constrained and is displaying correctly however the buttons are not. I have experimented by aligning button 1 with the leading edge of titleImage, and button2 with the trailing edge of titleImage, however the width distribution between the two buttons becomes skewed at this point, as demonstrated below.
我的目标是了解缺少哪些约束,并应将其应用于两个按钮以保持相同的宽度,而不管设备如何.如果可能的话,我想通过界面生成器而不是附加代码来实现这一点.
My objective is to understand what constraints are missing and should be applied to the two buttons to maintain equal widths regardless of device. If possible I would like to achieve this through interface builder as opposed to additional code.
推荐答案
添加如下约束
- 从 button1 到 button2 分配相等的宽度.
- 在两个按钮之间分配水平间距.
- 将 button1 的前导空格分配给其父视图.
- 将 button2 的尾随空格分配给其父视图.
- 为两个按钮分配顶部空间.<小时>请让我知道这对你有没有用.
这篇关于iOS自动布局:两个等宽的按钮,并排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS自动布局:两个等宽的按钮,并排
基础教程推荐
- 固定小数的Android Money Input 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
