Swiftpack.co - Package - Loupehope/OTPSwiftView

OTPSwiftView

Version Platform License

A fully customizable OTP view.

Usage

class ViewController: UIViewController {
    let otpView = CustomOTPSwiftView() // Custom OTP view

    let config = OTPCodeConfig(codeSymbolsCount: 6, // Base configuration of OTP view
                               spacing: 6,
                               customSpacing: [2: 20])

    override func viewDidLoad() {
        super.viewDidLoad()

        /* 
          Add your codeView and set layout 
        */
        
        /* Configure OTP view */
        
        otpView.configure(with: config)
        
        /* Bind events */
        
        otpView.onTextEnter = { code in
            // Get code from codeView
        }
        
        /* Update text */
        
        otpView.code = "234435"
        
        /* Update focus */
        
        otpView.focus = true|false
    }
}

Customization

Single OTP View

OTPView is a base class that describes a single OTP textfield.
To customize the appearance and layout, you must inherit from the OTPView.
Don't forget to add UIGestureRecognizer to call closure onTap?().

import OTPSwiftView

class CustomOTPView: OTPView {
    override func addViews() {
        super.addViews()
        
        // Adding additional views to current view. The OTP textfield has already been added.
    }
    
    override func configureLayout() {
        super.configureLayout()
    
        // Confgiure layout of subviews
    }
    
    override func bindViews() {
        super.bindViews()
        
        // Binding to data or user actions

        addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(onTap)))
    }
    
    override func configureAppearance() {
        super.configureAppearance()
        
        // Appearance configuration method
    }
}

OTPSwiftView

OTPSwiftView is a base class that is responsible for the layout of single OTP views.
As with OTPView, you should create an heir class to configure your full OTP view.

import OTPSwiftView

final class CustomOTPSwiftView: OTPSwiftView<CustomOTPView> {
    override func addViews() {
        super.addViews()
        
        // Adding additional views to current code view. The single OTP views has already been added.
    }
    
    override func configureLayout() {
        super.configureLayout()
        
        // Confgiure layout of subviews
    }
    
    override func bindViews() {
        super.bindViews()
        
        // Binding to data or user actions
    }
    
    override func configureAppearance() {
        super.configureAppearance()
        
        // Appearance configuration method
    }

    override func configure(with config: OTPCodeConfig) {
        super.configure(with: config)

        // Configure you code view with configuration
    }
}

Installation via SPM

package.append(.package(url: "https://github.com/Loupehope/TICodeView.git", from: "0.0.3"))

License

TICodeView is available under the Apache License 2.0. See the LICENSE file for more info.

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

0.1.4 - 2020-08-21 23:40:34

0.1.3 - 2020-08-21 23:38:35

0.1.2 - 2020-08-21 23:15:37

0.1.1 - 2020-08-21 22:42:03

0.1.0 - 2020-08-21 22:32:56

0.0.3 - 2020-07-04 18:38:53

0.0.2 - 2020-07-03 21:14:37

0.0.1 - 2020-07-01 15:12:35