Ask Your Question
0

In SwiftUI, what is the method for a TextField to adjust its height automatically according to its content?

asked 2022-08-31 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-09-08 09:00:00 +0000

devzero gravatar image

To allow a TextField to adjust its height automatically according to its content, set the .fixedSize(horizontal: false, vertical: true) modifier to it. This will cause the text field to wrap its contents vertically and grow or shrink dynamically based on the size of the text entered. For example:

TextField("Enter some text...", text: $text)
   .textFieldStyle(RoundedBorderTextFieldStyle())
   .fixedSize(horizontal: false, vertical: true)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-31 11:00:00 +0000

Seen: 11 times

Last updated: Sep 08 '21