Last active
May 16, 2020 20:20
-
-
Save markiv/8e1fc829a2b6effb3ee692cbb2ffd67e to your computer and use it in GitHub Desktop.
FloatingTextField4.swift
This file contains 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(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