Skip to content

Instantly share code, notes, and snippets.

@markiv
Created May 16, 2020 16:35
Show Gist options
  • Select an option

  • Save markiv/bc43d7c295a883d4e0f1e2138f04a309 to your computer and use it in GitHub Desktop.

Select an option

Save markiv/bc43d7c295a883d4e0f1e2138f04a309 to your computer and use it in GitHub Desktop.

Revisions

  1. markiv revised this gist May 16, 2020. No changes.
  2. markiv created this gist May 16, 2020.
    15 changes: 15 additions & 0 deletions FloatingTextField2.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    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)
    }
    }