Skip to content

Instantly share code, notes, and snippets.

@markiv
Created May 16, 2020 16:35
Show Gist options
  • Save markiv/bc43d7c295a883d4e0f1e2138f04a309 to your computer and use it in GitHub Desktop.
Save markiv/bc43d7c295a883d4e0f1e2138f04a309 to your computer and use it in GitHub Desktop.
FloatingTextField2.swift
struct FloatingTextField: View {
let title: String
let text: Binding<String>
var body: some View {
VStack(alignment: .leading, spacing: 2) {
Text(title)
.font(.caption)
.foregroundColor(Color(.placeholderText))
.opacity(text.wrappedValue.isEmpty ? 0 : 1)
.offset(y: text.wrappedValue.isEmpty ? 20 : 0)
TextField(title, text: text)
}.animation(.default)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment