forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabeledTextField.swift
More file actions
52 lines (46 loc) · 1.49 KB
/
LabeledTextField.swift
File metadata and controls
52 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// LabeledTextField.swift
// LoopKitUI
//
// Created by Nathaniel Hamming on 2020-02-27.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import SwiftUI
public struct LabeledTextField: View {
var label: String
var placeholder: String
@Binding var value: String
public init(label: String, placeholder: String = "", value: Binding<String>) {
self.label = label
self.placeholder = placeholder
_value = value
}
public var body: some View {
GeometryReader { geometry in
HStack(alignment: .firstTextBaseline, spacing: 0) {
Text(self.label)
.foregroundColor(.primary)
.frame(maxWidth: geometry.size.width/2, alignment: .leading)
Spacer()
TextField(self.placeholder, text: self.$value)
.foregroundColor(.secondary)
.multilineTextAlignment(.trailing)
.keyboardType(.alphabet)
.frame(maxWidth: geometry.size.width/2, alignment: .trailing)
}
}
}
}
struct LabelTextField_Previews: PreviewProvider {
static var previews: some View {
return Group {
PreviewWrapper()
}
}
struct PreviewWrapper: View {
@State(initialValue: "Overnight") var value: String
var body: some View {
LabeledTextField(label: "Name", placeholder: "Schedule Name", value: $value)
}
}
}