Code Monkey home page Code Monkey logo

swiftui-custom-textfield's Introduction

Logo

Swift 5.6 SwiftUI MIT License

SwiftUI Custom TextField

This repository developed with only swiftUI, there is no UIViewRepresentable.

Requirements

  • iOS 13.0+
  • Xcode 13+
  • Swift 5+

Swift Package Manager

CustomTextfield is available through Swift Package Manager. Add CustomTextField as a dependency to your Package.swift:

.package(url: "https://github.com/esatgozcu/SwiftUI-Custom-TextField", from: "main")

Customize config

You can set your config properties in @main so you don't need to set every time.

@main
struct ExampleApp: App {
    init() {
        let shared = EGTextFieldConfig.shared
        shared.defaultTextColor = .black
        shared.darkModeTextColor = .white
        shared.defaultTitleColor = .black
        shared.darkModeTitleColor = .white
        shared.titleFont = .body
        shared.borderType = .line
        ...
    }
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Dark Mode

Dark mode ability is available. You don't need to consider this issue. If you want to change default color you can set in config file.

Default initialize

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setTitleText("Title")

Light

Light Mode

Dark

Dark Mode

Examples

Default

@State var text = "Esat Gozcu"

EGTextField(text: $text)

Default

Line Border

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setBorderType(.line)

Line Border

Title

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setTitleText("Name")
                .setTitleColor(.blue)
                .setTitleFont(.body)

Title

PlaceHolder

@State var text = ""

EGTextField(text: $text)
                .setPlaceHolderText("Enter a name")

PlaceHolder

Also if you want you can change placeholder color

@State var text = ""

EGTextField(text: $text)
                .setPlaceHolderText("Enter a name")
                .setPlaceHolderTextColor(Color.gray)

Disable

@State var text = "Esat Gozcu"
@State var disable = true

EGTextField(text: $text)
                .setDisable($disable)
                .setDisableColor(Color.gray.opacity(0.2))

Disable

Bottom Error

@State var text = "Esat Gozcu"
@State var error = true
@State var errorText = "Your name is not matched"

EGTextField(text: $text)
                .setError(errorText: $errorText, error: $error)

Bottom Error

Trailing Image

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setTrailingImage(Image(systemName: "qrcode"), click: {
                    print("qr image tapped")
                })

Trailing Image

You can also set image foreground color.

EGTextField(text: $text)
                .setTrailingImageForegroundColor(.black)
                .setDarkModeTrailingImageForegroundColor(.white)

⚠️ Warning: If you do not use system image. When you add your image, you have to set your 'Render as -> Template Image'. Otherwise you can not use this foreground color feature.

Secure Text

@State var text = "Esat Gozcu"

EGTextField(text: $text)
               .setSecureText(true)

Secure Text Close

Secure Text Open

Secure text images can be changed

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setSecureText(true)
                .setSecureTextImages(open : Image(systemName: "eye.fill"),
                                     close: Image(systemName: "eye.slash.fill"))

Max Count

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setMaxCount(8)

Max Count

Truncation Mode

@State var text = "esat1feyk23mqjyefycrfk862x78cyk2sy9l0t8rt6c"

EGTextField(text: $text)
                .setTruncateMode(.middle)

Truncation Mode

Border Color and Width

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setBorderColor(.orange)
                .setBorderWidth(1.0)

Border Color

Text Color

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setTextColor(.blue)

Text Color

Background Color

@State var text = "Esat Gozcu"

EGTextField(text: $text)
            .setBackgroundColor(Color.black)
            .setTextColor(Color.white)

Background Color

Corner Radius

@State var text = "Esat Gozcu"

EGTextField(text: $text)
            .setCornerRadius(20.0)

Corner Radius

Disable Auto Correction

@State var text = "Esat Gozcu"

EGTextField(text: $text)
             .setDisableAutoCorrection(true)

Set Height

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setTextFieldHeight(45)

Focused Border Color

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setFocusedBorderColorEnable(true)

Normal

Focused

If you want you can change colors.

@State var text = "Esat Gozcu"

EGTextField(text: $text)
                .setFocusedBorderColorEnable(true)
                .setFocusedBorderColor(.black)
                .setDarkModeFocusedBorderColor(.white)

⚠️ Warning: This feauture is not working on secureField.

swiftui-custom-textfield's People

Contributors

esatgozcu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

swiftui-custom-textfield's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.