Skip to content

Commit bbbc806

Browse files
Initial Commit v1.0.0
1 parent 2e13335 commit bbbc806

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

Package.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// swift-tools-version: 6.2
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "FloatingLabelTextField",
8+
platforms: [
9+
.iOS(.v14)
10+
],
11+
products: [
12+
.library(
13+
name: "FloatingLabelTextField",
14+
targets: ["FloatingLabelTextField"]
15+
),
16+
],
17+
targets: [
18+
.target(
19+
name: "FloatingLabelTextField"
20+
),
21+
.testTarget(
22+
name: "FloatingLabelTextFieldTests",
23+
dependencies: ["FloatingLabelTextField"]
24+
),
25+
]
26+
)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// The Swift Programming Language
2+
// https://docs.swift.org/swift-book
3+
4+
5+
import SwiftUI
6+
7+
@available(iOS 15.0, *)
8+
public struct FloatingLabelTextField: View {
9+
public let label: String
10+
@Binding public var text: String
11+
public var placeholder: String?
12+
public var isSecure: Bool
13+
public var keyboardType: UIKeyboardType
14+
public var autocapitalization: TextInputAutocapitalization?
15+
16+
public init(
17+
label: String,
18+
text: Binding<String>,
19+
placeholder: String? = nil,
20+
isSecure: Bool = false,
21+
keyboardType: UIKeyboardType = .default,
22+
autocapitalization: TextInputAutocapitalization? = .sentences
23+
){
24+
self.label = label
25+
self._text = text
26+
self.placeholder = placeholder
27+
self.isSecure = isSecure
28+
self.keyboardType = keyboardType
29+
self.autocapitalization = autocapitalization
30+
}
31+
32+
public var body: some View {
33+
ZStack(alignment: .leading){
34+
RoundedRectangle(cornerRadius: 6, style: .continuous)
35+
.stroke(Color.primary.opacity(0.9), lineWidth: 1)
36+
.background(Color(UIColor.systemBackground))
37+
38+
VStack(alignment: .leading, spacing: 0){
39+
Text(label)
40+
.font(.system(size: 14))
41+
.foregroundColor(Color.primary)
42+
.padding(.horizontal, 6)
43+
.background(Color(UIColor.systemBackground))
44+
.offset(x: 12, y: -10)
45+
.zIndex(1)
46+
47+
Group {
48+
if isSecure {
49+
SecureField(placeholder ?? "", text: $text)
50+
.textInputAutocapitalization(autocapitalization)
51+
.keyboardType(keyboardType)
52+
} else {
53+
TextField(placeholder ?? "", text: $text)
54+
.textInputAutocapitalization(autocapitalization)
55+
.keyboardType(keyboardType)
56+
}
57+
}
58+
.padding(.horizontal, 12)
59+
.padding(.vertical, 10)
60+
}
61+
.padding(.top, 6)
62+
}
63+
.frame(minHeight: 48)
64+
}
65+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Testing
2+
@testable import FloatingLabelTextField
3+
4+
@Test func example() async throws {
5+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
6+
}

0 commit comments

Comments
 (0)