BYCustomTextField is a customizable text input component developed using Swift and UIKit. In addition to the standard UITextField component, it offers a more flexible and customizable experience.
1- Open your project in Xcode.
2- Click File > Add Packages...
3- Enter the following URL and click the Add Package button:
https://github.com/bayramyelec/BYCustomTextField


import BYCustomTextField
.
.
let emailTextField = BYTextField(placeholder: "E-mail", alertMessage: "Lütfen geçerli bir e-mail adresi girin.", validMessage: "Geçerli e-mail adresi.", characters: ["@", "."])
emailTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(emailTextField)
NSLayoutConstraint.activate([
emailTextField.widthAnchor.constraint(equalToConstant: 350)
emailTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor)
emailTextField.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
import BYCustomTextFieldSwiftUI
.
.
@State var text: String = ""
.
.
BYTextFieldSwiftUI(text: $text, placeholder: "E-mail", alertText: "Lütfen geçerli bir e-mail girin.", validText: "Geçerli email.", characters: ["@", "."], textColor: Color.black, leftIcon: "person.fill", leftIconColor: Color.gray)
Parameter | Type | Description |
---|---|---|
placeholder |
string |
Textfield Placeholder.. |
alertMessage |
string |
Warning message for text field.. |
validMessage |
string |
The text that appears when you enter correct text.. |
backColor |
UIColor? |
Background color of text field.. |
textColor |
UIColor? |
text color of the text field.. |
characters |
[String] |
Required symbols for warning message.. |
leftIcon |
String |
left icon systemName... |
leftIconColor |
Color |
left icon color.. |
import BYCustomTextField
.
.
let passwordTextField = BYSecurityTextField(placeHolder: "Password", alertMessage: "Şifreniz en az 6 haneli olmalı.", validMessage: "Geçerli şifre.", minCharacterCount: 6)
passwordTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(passwordTextField)
NSLayoutConstraint.activate([
passwordTextField.widthAnchor.constraint(equalToConstant: 350)
passwordTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor)
passwordTextField.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
import BYCustomTextFieldSwiftUI
.
.
@State var text: String = ""
.
.
BYSecurityTextFieldSwiftUI(text: $text1, placeholder: "Password", alertText: "Şifreniz en az 5 haneli olmalıdır.", validText: "Geçerli şifre.", characterCount: 5, textColor: Color.black, leftIcon: "lock.fill", leftIconColor: Color.gray)
Parameter | Type | Description |
---|---|---|
placeholder |
string |
Textfield Placeholder.. |
alertMessage |
string |
Warning message for text field.. |
validMessage |
string |
The text that appears when you enter correct text.. |
backColor |
UIColor? |
Background color of text field.. |
textColor |
UIColor? |
text color of the text field.. |
minCharacterCount |
Int? |
Minimum number of characters.. |
leftIcon |
String |
left icon systemName... |
leftIconColor |
Color |
left icon color.. |
import BYCustomTextField
.
.
let emailUnderlineTextField = BYUnderlineTextField(leftIcon: UIImage(systemName: "person.fill") ?? UIImage(), placeholder: "E-mail", alertMessage: "Lütfen geçerli bir e-mail adresi girin.", validMessage: "Geçerli e-mail adresi.", underlineColor: .black, characters: ["@", "."])
emailUnderlineTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(emailUnderlineTextField)
NSLayoutConstraint.activate([
emailUnderlineTextField.widthAnchor.constraint(equalToConstant: 350)
emailUnderlineTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor)
emailUnderlineTextField.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
import BYCustomTextFieldSwiftUI
.
.
@State var text: String = ""
.
.
BYUnderlineTextFieldSwiftUI(text: $text2, placeholder: "E-mail", alertText: "Lütfen geçerli bir e-mail girin.", validText: "Geçerli email.", characters: ["@", "."], textColor: Color.black, underLineColor: Color.gray, leftIcon: "person.fill")
Parameter | Type | Description |
---|---|---|
placeholder |
string |
Textfield Placeholder.. |
alertMessage |
string |
Warning message for text field.. |
validMessage |
string |
The text that appears when you enter correct text.. |
underlineColor |
UIColor |
Underline color of text field.. |
backColor |
UIColor? |
Background color of text field.. |
textColor |
UIColor? |
Text color of the text field.. |
characters |
[String] |
Required symbols for warning message.. |
leftIcon |
String |
left icon systemName... |
leftIconColor |
Color |
left icon color.. |
import BYCustomTextField
.
.
let passwordUnderlineTextField = BYUnderlineSecurityTextField(leftIcon: UIImage(systemName: "key.horizontal.fill") ?? UIImage(), placeholder: "Password", alertMessage: "Şifreniz en az 6 haneli olmalı.", validMessage: "Geçerli şifre.", underlineColor: .black, minCharacterCount: 6)
passwordUnderlineTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(passwordUnderlineTextField)
NSLayoutConstraint.activate([
passwordUnderlineTextField.widthAnchor.constraint(equalToConstant: 350)
passwordUnderlineTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor)
passwordUnderlineTextField.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
import BYCustomTextFieldSwiftUI
.
.
@State var text: String = ""
.
.
BYUnderlineSecurityTextFieldSwiftUI(text: $text3, placeholder: "Password", alertText: "Şifreniz en az 5 haneli olmalıdır.", validText: "Geçerli şifre.", minCharacterCount: 5, textColor: Color.black, underLineColor: Color.gray, leftIcon: "lock.fill")
Parameter | Type | Description |
---|---|---|
placeholder |
string |
Textfield Placeholder.. |
alertMessage |
string |
Warning message for text field.. |
validMessage |
string |
The text that appears when you enter correct text.. |
underlineColor |
UIColor |
Underline color of text field.. |
backColor |
UIColor? |
Background color of text field.. |
textColor |
UIColor? |
Text color of the text field.. |
minCharacterCount |
Int? |
Minimum number of characters.. |
leftIcon |
String |
left icon systemName... |
leftIconColor |
Color |
left icon color.. |
class ViewController: UIViewController, UITextFieldDelegate {
let customTextField = BYTextField(placeholder: "E-mail", alertMessage: "Lütfen geçerli bir e-mail adresi girin.", validMessage: "Geçerli e-mail adresi.", characters: ["@", "."])
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(customTextField)
customTextField.delegate = self
customTextField.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
customTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor),
customTextField.centerYAnchor.constraint(equalTo: view.centerYAnchor),
customTextField.widthAnchor.constraint(equalToConstant: 250),
])
}
func textFieldDidBeginEditing(_ textField: UITextField) {
print("Kullanıcı giriş yapmaya başladı")
}
func textFieldDidEndEditing(_ textField: UITextField) {
print("Kullanıcı giriş yapmayı bitirdi")
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}