Skip to content

Instantly share code, notes, and snippets.

@markiv
Last active May 16, 2020 20:20
Show Gist options
  • Save markiv/8e1fc829a2b6effb3ee692cbb2ffd67e to your computer and use it in GitHub Desktop.
Save markiv/8e1fc829a2b6effb3ee692cbb2ffd67e to your computer and use it in GitHub Desktop.
FloatingTextField4.swift
struct FloatingTextField: View {
let title: String
let text: Binding<String>
var body: some View {
ZStack(alignment: .leading) {
Text(title)
.foregroundColor(text.wrappedValue.isEmpty ? Color(.placeholderText) : .accentColor)
.offset(y: text.wrappedValue.isEmpty ? 0 : -25)
.scaleEffect(text.wrappedValue.isEmpty ? 1 : 0.75, anchor: .leading)
TextField("", text: text)
}
.padding(.top, 15)
.animation(.spring(response: 0.4, dampingFraction: 0.3))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment