Skip to content

Commit 9c003f6

Browse files
committed
feat: Add width and height
1 parent cbf0cba commit 9c003f6

4 files changed

Lines changed: 69 additions & 14 deletions

File tree

Example/Example.xcodeproj/project.pbxproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
A42AB368260B474E001422E8 /* RespondableTextField in Frameworks */ = {isa = PBXBuildFile; productRef = A42AB367260B474E001422E8 /* RespondableTextField */; };
1011
A4C784C7258B91B7009BB00C /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4C784C6258B91B7009BB00C /* ExampleApp.swift */; };
1112
A4C784C9258B91B7009BB00C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A4C784C8258B91B7009BB00C /* ContentView.swift */; };
1213
A4C784CB258B91B9009BB00C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A4C784CA258B91B9009BB00C /* Assets.xcassets */; };
1314
A4C784CE258B91B9009BB00C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A4C784CD258B91B9009BB00C /* Preview Assets.xcassets */; };
14-
A4C784DB258B9213009BB00C /* RespondableTextField in Frameworks */ = {isa = PBXBuildFile; productRef = A4C784DA258B9213009BB00C /* RespondableTextField */; };
15-
A4C784DC258B9213009BB00C /* RespondableTextField in Embed Frameworks */ = {isa = PBXBuildFile; productRef = A4C784DA258B9213009BB00C /* RespondableTextField */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
1615
/* End PBXBuildFile section */
1716

1817
/* Begin PBXCopyFilesBuildPhase section */
@@ -22,7 +21,6 @@
2221
dstPath = "";
2322
dstSubfolderSpec = 10;
2423
files = (
25-
A4C784DC258B9213009BB00C /* RespondableTextField in Embed Frameworks */,
2624
);
2725
name = "Embed Frameworks";
2826
runOnlyForDeploymentPostprocessing = 0;
@@ -44,7 +42,7 @@
4442
isa = PBXFrameworksBuildPhase;
4543
buildActionMask = 2147483647;
4644
files = (
47-
A4C784DB258B9213009BB00C /* RespondableTextField in Frameworks */,
45+
A42AB368260B474E001422E8 /* RespondableTextField in Frameworks */,
4846
);
4947
runOnlyForDeploymentPostprocessing = 0;
5048
};
@@ -114,7 +112,7 @@
114112
);
115113
name = Example;
116114
packageProductDependencies = (
117-
A4C784DA258B9213009BB00C /* RespondableTextField */,
115+
A42AB367260B474E001422E8 /* RespondableTextField */,
118116
);
119117
productName = Example;
120118
productReference = A4C784C3258B91B7009BB00C /* Example.app */;
@@ -361,7 +359,7 @@
361359
/* End XCConfigurationList section */
362360

363361
/* Begin XCSwiftPackageProductDependency section */
364-
A4C784DA258B9213009BB00C /* RespondableTextField */ = {
362+
A42AB367260B474E001422E8 /* RespondableTextField */ = {
365363
isa = XCSwiftPackageProductDependency;
366364
productName = RespondableTextField;
367365
};

Example/Example/ContentView.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ struct ContentView: View {
2828
Group {
2929
Text("Default")
3030
.font(.system(size: 14, weight: .bold, design: .default))
31-
RespondableTextField(text: $text1, tag: 0, isFirstResponder: true, placeholder: "1st") { value in
31+
RespondableTextField(text: $text1,
32+
tag: 0,
33+
isFirstResponder: true,
34+
placeholder: "1st") { value in
3235
print("onEditing: \(value)")
3336
} didBeginEditing: {
3437
print("didBeginEditing")
@@ -45,7 +48,11 @@ struct ContentView: View {
4548
Group {
4649
Text("SecureType + RectangleLine Border")
4750
.font(.system(size: 14, weight: .bold, design: .default))
48-
RespondableTextField(text: $text2, tag: 1, placeholder: "2nd") { value in
51+
RespondableTextField(text: $text2,
52+
tag: 1,
53+
placeholder: "2nd",
54+
width: 200,
55+
height: 50) { value in
4956
print("onEditing: \(value)")
5057
} didBeginEditing: {
5158
print("didBeginEditing")
@@ -64,7 +71,9 @@ struct ContentView: View {
6471
Group {
6572
Text("NumberPad + OneTimeCode + Rounded Border")
6673
.font(.system(size: 14, weight: .bold, design: .default))
67-
RespondableTextField(text: $text3, tag: 2, placeholder: "3rd") { value in
74+
RespondableTextField(text: $text3,
75+
tag: 2,
76+
placeholder: "3rd") { value in
6877
print("onEditing: \(value)")
6978
} didBeginEditing: {
7079
print("didBeginEditing")
@@ -84,7 +93,9 @@ struct ContentView: View {
8493
Group {
8594
Text("didBeginEditing + didEndEditing + Bazel Border")
8695
.font(.system(size: 14, weight: .bold, design: .default))
87-
RespondableTextField(text: $text4, tag: 3, placeholder: "4th") { value in
96+
RespondableTextField(text: $text4,
97+
tag: 3,
98+
placeholder: "4th") { value in
8899
print("onEditing: \(value)")
89100
} didBeginEditing: {
90101
print("didBeginEditing")

README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
tag: Int,
3535
isFirstResponder: Bool = false,
3636
placeholder: String? = nil,
37+
width: CGFloat? = nil,
38+
height: CGFloat? = nil,
3739
onEditing: ((String) -> Void)? = nil,
3840
didBeginEditing: (() -> Void)? = nil,
3941
didEndEditing: (() -> Void)? = nil,
@@ -44,6 +46,25 @@
4446
- Also, you don't have to fill all of the optional parameters or `isFirstResponder`.
4547
- You can make the textField the first responder with `isFirstResponder = true`.
4648

49+
## Extensions
50+
51+
- `respondableSecureType()`
52+
- Secure type
53+
- `respondableKeyboardType(_ type: UIKeyboardType)`
54+
- Change keyboard type
55+
- `respondableContentType(_ type: UITextContentType)`
56+
- Change content type
57+
- `respondableCapitalization(_ type: UITextAutocapitalizationType)`
58+
- Capitalization change
59+
- `respondableFont(_ font: UIFont)`
60+
- Change font
61+
- `respondableLineStyle()`
62+
- Borderstyle: .line
63+
- `respondableBezelStyle()`
64+
- Borderstyle: .bezel
65+
- `textFieldStyle<S>(_ style: S) -> some View where S: TextFieldStyle`
66+
- Borderstyle: .roundedRect, .none
67+
4768
## Example
4869

4970
You can use or customize RespondableTextField like below, or [see example file](./Example/Example/ContentView.swift).
@@ -79,7 +100,10 @@ struct ContentView: View {
79100
Group {
80101
Text("Default")
81102
.font(.system(size: 14, weight: .bold, design: .default))
82-
RespondableTextField(text: $text1, tag: 0, isFirstResponder: true, placeholder: "1st") { value in
103+
RespondableTextField(text: $text1,
104+
tag: 0,
105+
isFirstResponder: true,
106+
placeholder: "1st") { value in
83107
print("onEditing: \(value)")
84108
} didBeginEditing: {
85109
print("didBeginEditing")
@@ -96,7 +120,11 @@ struct ContentView: View {
96120
Group {
97121
Text("SecureType + RectangleLine Border")
98122
.font(.system(size: 14, weight: .bold, design: .default))
99-
RespondableTextField(text: $text2, tag: 1, placeholder: "2nd") { value in
123+
RespondableTextField(text: $text2,
124+
tag: 1,
125+
placeholder: "2nd",
126+
width: 200,
127+
height: 50) { value in
100128
print("onEditing: \(value)")
101129
} didBeginEditing: {
102130
print("didBeginEditing")
@@ -115,7 +143,9 @@ struct ContentView: View {
115143
Group {
116144
Text("NumberPad + OneTimeCode + Rounded Border")
117145
.font(.system(size: 14, weight: .bold, design: .default))
118-
RespondableTextField(text: $text3, tag: 2, placeholder: "3rd") { value in
146+
RespondableTextField(text: $text3,
147+
tag: 2,
148+
placeholder: "3rd") { value in
119149
print("onEditing: \(value)")
120150
} didBeginEditing: {
121151
print("didBeginEditing")
@@ -135,7 +165,9 @@ struct ContentView: View {
135165
Group {
136166
Text("didBeginEditing + didEndEditing + Bazel Border")
137167
.font(.system(size: 14, weight: .bold, design: .default))
138-
RespondableTextField(text: $text4, tag: 3, placeholder: "4th") { value in
168+
RespondableTextField(text: $text4,
169+
tag: 3,
170+
placeholder: "4th") { value in
139171
print("onEditing: \(value)")
140172
} didBeginEditing: {
141173
print("didBeginEditing")

Sources/RespondableTextField/RespondableTextField.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public struct RespondableTextField: UIViewRepresentable {
3030
tag: Int,
3131
isFirstResponder: Bool = false,
3232
placeholder: String? = nil,
33+
width: CGFloat? = nil,
34+
height: CGFloat? = nil,
3335
onEditing: ((String) -> Void)? = nil,
3436
didBeginEditing: (() -> Void)? = nil,
3537
didEndEditing: (() -> Void)? = nil,
@@ -39,6 +41,17 @@ public struct RespondableTextField: UIViewRepresentable {
3941
self.tag = tag
4042
self.isFirstResponder = isFirstResponder
4143
self.placeholder = placeholder
44+
45+
if let width = width {
46+
textField.translatesAutoresizingMaskIntoConstraints = false
47+
textField.widthAnchor.constraint(equalToConstant: width).isActive = true
48+
}
49+
50+
if let height = height {
51+
textField.translatesAutoresizingMaskIntoConstraints = false
52+
textField.heightAnchor.constraint(equalToConstant: height).isActive = true
53+
}
54+
4255
self.onEditing = onEditing
4356
self.didBeginEditing = didBeginEditing
4457
self.didEndEditing = didEndEditing
@@ -146,6 +159,7 @@ extension RespondableTextField {
146159

147160
}
148161

162+
149163
}
150164

151165
// MARK: - KEYBOARD & CONTENT

0 commit comments

Comments
 (0)