> ## Content Index
> Fetch the complete content index at: https://yinguobing.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# Swift: Build a Basic UI
- URL: https://yinguobing.com/blog/swift-build-a-basic-ui/
- Published: 2015-09-05T21:18:39.000Z
- Updated: 2022-05-29T07:32:33.000Z
- Description: Text Field中的Placeholder是啥东西。
- Author: 尹国冰
- Tags: Swift

在设置了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](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/GlossaryDefinitions.html?ref=yinguobing.com#//apple%5Fref/doc/uid/TP40015214-CH12-SW110). 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字符串，但是实际使用中用户输入的文本可以比这个长。