GithubHelp home page GithubHelp logo

textfieldview's Introduction

TextFieldView

TextFieldView with Error and Title labels. Currently It'll be used with storyboard only.

Demo

Yotube Preview:

Alt text

Code:

import UIKit
import TextFieldView

final class ViewController: UIViewController {

    @IBOutlet
    private weak var textField: TextFieldView!

    @IBOutlet
    private weak var buttonClick: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.textField.delegate = self
        self.setButton(isValid: false)
    }

    @IBAction
    private func actionClick(_ sender: UIButton) {

        guard let email = self.textField.text else {

            return
        }

        print("Email: \(email)")
    }
}

// MARK: TextFieldViewDelegate
extension ViewController: TextFieldViewDelegate {

    func textFieldView(_ textFieldView: TextFieldView, didValidated isValid: Bool) {

        self.setButton(isValid: isValid)
    }

    private func setButton(isValid: Bool) {
        self.buttonClick.backgroundColor = isValid ? #colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1) : #colorLiteral(red: 0.855728209, green: 0.855728209, blue: 0.855728209, alpha: 1)
        self.buttonClick.isEnabled = isValid
    }

    func textFieldViewDidEndEditing(_ textFieldView: TextFieldView) {
        let alertVC = UIAlertController(title: "Finished", message: "is valid: \(textFieldView.isValid)", preferredStyle: .alert)

        alertVC.addAction(.init(title: "Ok", style: .cancel, handler: { _ in

            // TEST
//            if textFieldView.isValid {
//
//                textFieldView.textField.becomeFirstResponder()
//
//            } else {
//
//                textFieldView.textField.resignFirstResponder()
//            }

        }))

        self.present(alertVC, animated: true)
    }
}

Contribute

I would love you for the contribution to TextFieldView, check the LICENSE file for more info.

Meta

Rajamohan S โ€“ (https://rajamohan-s.github.io/)

Distributed under the GNU GENERAL PUBLIC license. See LICENSE for more information.

textfieldview's People

Contributors

rajamohan0s avatar

Watchers

 avatar

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.