Last active
May 16, 2020 21:30
-
-
Save markiv/3c2bf128bbf0ae24c2e36a60771a0b12 to your computer and use it in GitHub Desktop.
FloatingTextField3.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct FloatingTextField: View { | |
| let title: String | |
| let text: Binding<String> | |
| var body: some View { | |
| ZStack(alignment: .leading) { | |
| Text(title) | |
| .foregroundColor(Color(.placeholderText)) | |
| .offset(y: text.wrappedValue.isEmpty ? 0 : -25) | |
| .scaleEffect(text.wrappedValue.isEmpty ? 1 : 0.8, anchor: .leading) | |
| TextField("", text: text) // give TextField an empty placeholder | |
| } | |
| .padding(.top, 15) | |
| .animation(.spring(response: 0.2, dampingFraction: 0.5)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment