Resize UITextField horizontally with text using Auto Layout

前端 未结 1 1692
野的像风
野的像风 2021-01-04 23:10

An example project to demonstrate the below issue can be found here: https://github.com/markdorison/UITextFieldContentSizeExample/

I am attempting to have a UITextFi

相关标签:
1条回答
  • 2021-01-04 23:51

    I am setting a placeholder. However wide the placeholder is, the width of the UITextField's intrinsicContentSize will never drop below it. So if the placeholder's width is 130, and I begin to type, the text view's width will remain at 130 until what I am typing reaches a width greater than 130; after this the text view will grow.

    I think you'll have to use a UITextField subclass where you get to set the instrinsicContentSize, overriding the default behavior of the intrinsicContentSize method which is evidently to size based on the placeholder.

    0 讨论(0)
提交回复
热议问题