Skip to content

Instantly share code, notes, and snippets.

@markiv
Last active May 16, 2020 21:30
Show Gist options
  • Save markiv/3c2bf128bbf0ae24c2e36a60771a0b12 to your computer and use it in GitHub Desktop.
Save markiv/3c2bf128bbf0ae24c2e36a60771a0b12 to your computer and use it in GitHub Desktop.
FloatingTextField3.swift
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