简体   繁体   中英

Can I use Auto Layout to resize my window according to a label size?

I have a window with a form like this:

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

Now I would like to localize the app. The translated labels could be much longer, is it possible for them to “push” the width of the window using Auto Layout?

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

Sure! If the labels don't have a fixed width, they grow automatically. Simply set leading and trailing constraints and they try to get the space they need.

You can test this in Xcode as well using the preview feature:

英语 其他一些语言

And here are the constraints that are used in this example:

约束条件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM