Skip to content

SwiftUI TextField where the width is automatically made as small as possible

Notifications You must be signed in to change notification settings

joehinkle11/TextFieldDynamicWidth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

TextFieldDynamicWidth

SwiftUI TextField where the width is automatically made as small as possible. I used this in one of my projects and saw some people on Reddit were having trouble solving this problem. Just copy the TextFieldDynamicWidth.swift file to you project to use.

Example

HStack(spacing: 0) {
  TextFieldDynamicWidth(title: "Type something here!", text: $editingText) { editingChange in
    // logic
  } onCommit: {
    // logic
  }.font(.title).multilineTextAlignment(.center)
  Text("This text will appear immediately to the right of the text field")
}

Notes

I have 0 intention of maintaining this. I just wanted to help out those Redditors. If there is a problem or an improvement you want, make a pull request and I'll approve it.

Reddit post: https://www.reddit.com/r/SwiftUI/comments/eq1a9o/how_to_make_textfielduitextfield_change_width_and/

About

SwiftUI TextField where the width is automatically made as small as possible

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages