FloatingField("title", text: $statevar)
.textFieldStyle(RoundedBorderTextFieldStyle())
.keyboardType(.asciiCapable)
struct FloatingField: View {
@Binding private var text: String
private var title: String
init(_ title: String, text: Binding<String>) {
self.title = title
self._text = text
}
var body: some View {
ZStack {
HStack {
TextField(title, text: $text)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
if !text.isEmpty {
HStack {
Text(title)
.font(.caption)
.background(.white)
Spacer()
}.offset(x: 7, y: -17)
}
}
}
}
댓글
댓글 쓰기