Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add Dots instead of showing number ? #1

Open
MithunReddy opened this issue Jan 11, 2016 · 8 comments
Open

How to add Dots instead of showing number ? #1

MithunReddy opened this issue Jan 11, 2016 · 8 comments

Comments

@MithunReddy
Copy link

No description provided.

@ma11hew28
Copy link
Member

You can't. Well, at least not without editing the source code. I.e., there's no property you can set, like the secureTextEntry property of UITextInputTraits. Although, that would be a cool option and should be fairly easy to add. See if you can figure it out. ;-)

See also https://github.com/venmo/VENTouchLock.

@MithunReddy
Copy link
Author

how to set "secureTextEntry" in swift can u help me in that. i tried below code and "var secureTextEntry: Bool { get{ return true} set {} }" and got an error
screen shot 2016-01-13 at 7 36 22 pm

@ma11hew28
Copy link
Member

Hmm... Try asking on Stack Overflow.

@ma11hew28
Copy link
Member

Here's the basic idea.

  • On line 43, change the last word text to a dot "•"
  • Add a String property called code to store the code
  • Update code accordingly in deleteBackward & insertText:

Bonus

  • Add a Bool property called secureTextEntry
  • If true, use dots; else, use text

Note: Don't make CodeInputView conform to UITextInputTraits.

@chandanvarma009
Copy link

import UIKit

class CodeInputView: UIView, UIKeyInput {
var delegate: CodeInputViewDelegate?
var nextTag = 1
var secureCode = ""
var secure:Bool = false
// MARK: - UIResponder

override func canBecomeFirstResponder() -> Bool {
    return true
}

// MARK: - UIView

override init(frame: CGRect) {
    super.init(frame: frame)

    // Add four digitLabels
    var frame = CGRect(x: 5, y: 0, width: 55, height: 55)
    for index in 1...4 {
        let digitLabel = UILabel(frame: frame)
        digitLabel.font = UIFont.systemFontOfSize(42)
        digitLabel.backgroundColor = UIColor.yiWhiteColor()
        digitLabel.tag = index
        digitLabel.text = " "
        digitLabel.textAlignment = .Center
        self.addSubview(digitLabel)
        frame.origin.x += 55 + 10
    }
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

// MARK: - UIKeyInput

func hasText() -> Bool {
    return nextTag > 1 ? true : false
}



func insertText(text: String) {

    if nextTag < 5 {
        (self.viewWithTag(nextTag) as! UILabel).text = text

        if (nextTag == 1){
         secureCode = (self.viewWithTag(nextTag) as! UILabel).text!
        } else {
         secureCode += (self.viewWithTag(nextTag) as! UILabel).text!
        }
        if secure == true {
            (self.viewWithTag(nextTag) as! UILabel).text! = "\u{2022}"
        }

        nextTag += 1

        if nextTag == 5 {

            delegate?.codeInputView(self, didFinishWithCode: secureCode)

        }
    }
}

func deleteBackward() {
    if nextTag > 1 {
        nextTag -= 1
        (self.viewWithTag(nextTag) as! UILabel).text = " "

        secureCode = String(secureCode.characters.dropLast())
    }
}

func clear() {
    while nextTag > 1 {
        deleteBackward()
    }
}

// MARK: - UITextInputTraits

var keyboardType: UIKeyboardType { get { return .NumberPad } set { } }

}

protocol CodeInputViewDelegate {
func codeInputView(codeInputView: CodeInputView, didFinishWithCode code: String)
}

@chandanvarma009
Copy link

chandanvarma009 commented Apr 24, 2016

Use it as codeInputView?.secure = true will display your text securely as dot i.e. \u{2022}

@MithunReddy
Copy link
Author

That works !!! Thanks @chandanvarma009

@aditya-capsitech
Copy link

how to set auto fill otp in this??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants