/TvCodeScreen

๐Ÿ–‹ Apple TV | Simple code screen

Primary LanguageSwiftMIT LicenseMIT

Version License Platform Build Status codecov.io

TvCodeScreen

Simple code screen for tvOS

You can download this repository and see this example app.

How to use

Install

In Podfile add

pod 'TvCodeScreen'

and use pod install.

Setup

Create a new UIView and set CodeInputView as a custom class

In Attribute Inspector tab you can change the code length and colors. The default code length value is 6 characters.

Then, your view controller need subscriber the CodeInputViewDelegate protocol. For example:

class ViewController: UIViewController {

    @IBOutlet weak var myCodeInputView: CodeInputView!
    @IBOutlet weak var labelResult: UILabel!
    
    override func viewDidLoad() {
        myCodeInputView.delegate = self
    }
}

extension ViewController: CodeInputViewDelegate {
    
    func finishTyping(_ codeInputView: CodeInputView, codeText: String) {
        if codeText == "42" {
            labelResult.text = "Yes! Good number! ๐ŸŽ‰"
        } else {
            labelResult.text = "No! Wrong number! ๐Ÿ’ฅ"
        }
    }
}

The function finishTyping(codeInputView:codeText:) is called when the user fill the code, and the parameter codeText is the text typed by user.

TODO

  • Use dynamic type
  • Suport for letters

Maintainer:

macabeus  ยท  GitHub @macabeus