/ Swift

Swift: Build a Basic UI

在设置了Text Field的Constrain之后,在attribute inspector中还需要将Content Compression Resistance Priority的Intrinsic Size修改为“Placeholder”。官方解释是这样的:

Text fields are sized based on their contents, which define their intrinsic content size. Intrinsic content size refers to the minimum size needed to display all the content in the view. You can assign UI elements a placeholder intrinsic content size if you need to design a UI for a different size than you can anticipate at design time. Right now, the text field’s only content is its placeholder string, but the actual text a user enters could be longer than that.


Text fields的大小取决于他们的内容,内容决定了固有内容尺寸(intrinsic content size)。固有内容尺寸是指能够显示view中所有内容的最小尺寸。如果你的UI在运行时可能与设计时不一样,那么在设计时可以给UI元素指定一个placeholder intrinsic content size。当前的text field仅有的内容就是placeholder字符串,但是实际使用中用户输入的文本可以比这个长。

Yin Guobing

Yin Guobing

BOE技术研发工程师🔬,业余码农😳,蓝猫铲屎官🐈。曾独立开发了一款iOS APP并上线🎉。现居北京,正在为了理想中的生活而奋斗..

Read More