macos - 我可以使用自动布局根据标签大小调整窗口大小吗?

标签 macos cocoa autolayout

我有一个带有如下形式的窗口:

+-------------------------------------------------+
|       Label one: [an image] [some other input]  |
|  A longer label: [an image] [another input]     |
+-------------------------------------------------+

现在我想本地化该应用程序。翻译后的标签可能会更长,它们是否可以使用自动布局“推”窗口的宽度?

+------------------------------------------------------+
|            Label one: [an image] [some other input]  |
|  A much longer label: [an image] [another input]     |
+------------------------------------------------------+

最佳答案

当然!如果标签没有固定宽度,它们会自动增长。只需设置前导和尾随约束,他们就会尝试获得所需的空间。

您也可以使用预览功能在 Xcode 中对此进行测试:

English Some other language

以下是此示例中使用的约束:

Constraints

关于macos - 我可以使用自动布局根据标签大小调整窗口大小吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067455/

相关文章:

macos - 闪光错误: The update is improperly signed

mysql - Sequel Pro/MAMP 在哪里存储本地数据库?

cocoa-touch - 检查dispatch_queue_t 上的相等性

objective-c - Xcode 不断告诉我 NSDirectoryEnumerator 的使用是错误的。

ios - TabBarController 的自动布局问题

ios - AutoLayout:removeFromSuperview/removeConstraints 抛出异常并严重崩溃

xcode - 使用 Xcode 11 编译时 vm_protect 失败

objective-c - Cocoa 绑定(bind)和检查字符串内容

ios - 使用 AutoLayout/UIScrollView 设置约束时了解 UIView 高度

macos - 错误 : there was a problem with the editor "vi" -- while trying to edit a deployment file in a cluster