Skip to content

Commit ff3df5e

Browse files
Fixed the padding issues about height and width
1 parent 4c58a80 commit ff3df5e

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

Package.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
// swift-tools-version: 6.2
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
//
2+
// Package.swift
3+
//
4+
// Created by Usama Javed on 12/10/2025.
5+
//
6+
// Swift Package definition for FloatingLabelTextField.
7+
// Provides an outlined SwiftUI text field with a floating label.
8+
//
9+
// License: MIT License
10+
// Copyright © 2025 Usama Javed. All rights reserved.
11+
//
312

413
import PackageDescription
514

Sources/FloatingLabelTextField/FloatingLabelTextField.swift

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
// The Swift Programming Language
2-
// https://docs.swift.org/swift-book
3-
1+
//
2+
// FloatingLabelTextField.swift
3+
// FloatingLabelTextField
4+
//
5+
// Created by Usama Javed on 12/10/2025.
6+
//
7+
// A customizable SwiftUI text field with an outlined border and floating label.
8+
// Supports secure input, keyboard customization, and flexible UI configuration.
9+
//
10+
// License: MIT License
11+
// Copyright © 2025 Usama Javed. All rights reserved.
12+
//
413

514
import SwiftUI
615

@@ -12,27 +21,39 @@ public struct FloatingLabelTextField: View {
1221
public var isSecure: Bool
1322
public var keyboardType: UIKeyboardType
1423
public var autocapitalization: TextInputAutocapitalization?
24+
public var height: CGFloat
25+
public var cornerRadius: CGFloat
26+
public var borderColor: Color
27+
public var borderWidth: CGFloat
1528

1629
public init(
1730
label: String,
1831
text: Binding<String>,
1932
placeholder: String? = nil,
2033
isSecure: Bool = false,
2134
keyboardType: UIKeyboardType = .default,
22-
autocapitalization: TextInputAutocapitalization? = .sentences
35+
autocapitalization: TextInputAutocapitalization? = .sentences,
36+
height: CGFloat = 40,
37+
cornerRadius: CGFloat = 6,
38+
borderColor: Color = .primary,
39+
borderWidth: CGFloat = 1
2340
){
2441
self.label = label
2542
self._text = text
2643
self.placeholder = placeholder
2744
self.isSecure = isSecure
2845
self.keyboardType = keyboardType
2946
self.autocapitalization = autocapitalization
47+
self.height = height
48+
self.cornerRadius = cornerRadius
49+
self.borderColor = borderColor
50+
self.borderWidth = borderWidth
3051
}
3152

3253
public var body: some View {
3354
ZStack(alignment: .leading){
34-
RoundedRectangle(cornerRadius: 6, style: .continuous)
35-
.stroke(Color.primary.opacity(0.9), lineWidth: 1)
55+
RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
56+
.stroke(borderColor.opacity(0.9), lineWidth: borderWidth)
3657
.background(Color(UIColor.systemBackground))
3758

3859
VStack(alignment: .leading, spacing: 0){
@@ -56,10 +77,10 @@ public struct FloatingLabelTextField: View {
5677
}
5778
}
5879
.padding(.horizontal, 12)
59-
.padding(.vertical, 10)
80+
.padding(.vertical, 8)
6081
}
6182
.padding(.top, 6)
6283
}
63-
.frame(minHeight: 48)
84+
.frame(minHeight: height, maxHeight: height)
6485
}
6586
}

Tests/FloatingLabelTextFieldTests/FloatingLabelTextFieldTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
2+
//
3+
// FloatingLabelTextField.swift
4+
// FloatingLabelTextField
5+
//
6+
// Created by Usama Javed on 12/10/2025.
7+
//
8+
// A customizable SwiftUI text field with an outlined border and floating label.
9+
// Supports secure input, keyboard customization, and flexible UI configuration.
10+
//
11+
// License: MIT License
12+
// Copyright © 2025 Usama Javed. All rights reserved.
13+
//
14+
115
import Testing
216
@testable import FloatingLabelTextField
317

0 commit comments

Comments
 (0)