iOS自动布局:两个等宽的按钮,并排

2023-09-11移动开发问题
5

本文介绍了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.

推荐答案

添加如下约束

  1. 从 button1 到 button2 分配相等的宽度.
  2. 在两个按钮之间分配水平间距.
  3. 将 button1 的前导空格分配给其父视图.
  4. 将 button2 的尾随空格分配给其父视图.
  5. 为两个按钮分配顶部空间.<小时>请让我知道这对你有没有用.

这篇关于iOS自动布局:两个等宽的按钮,并排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7