Skip to content

implement FasterVerificationCode programatically #1

Open

Description

@d33pak-s1ngh

Hello @posix88 i am new to swift and ios. I want to implement this otp text field in my verfication view controller programatically. Do you have any example for this it will be help ful.

Following code i have tried
`

lazy var newVerification: VerificationCodeView = {
        let vv = VerificationCodeView()
        vv.translatesAutoresizingMaskIntoConstraints = false

    vv.setLabelNumber(6)
    vv.delegate = self
    vv.labelHasBorder = true
    vv.borderHeigth = 1
    vv.labelBorderColor = UIColor.black
    vv.labelErrorColor = UIColor.red
    vv.labelTextColor = UIColor.black
    //vv.labelBackgroundColor =
    vv.labelWidth = 24
    vv.isNumeric = true
    vv.labelSpacing = 16
    
    
    return vv
}()

func setupCode(){
    
    view.addSubview(newVerification)
    newVerification.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
    newVerification.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
    if #available(iOS 11.0, *) {
        newVerification.topAnchor.constraint(equalTo: view.topAnchor,constant: 50).isActive = true
    } else {
        // Fallback on earlier versions
    }
    newVerification.heightAnchor.constraint(equalToConstant: 80).isActive = true
    
}`

Activity

  1. d33pak-s1ngh commented on Jun 5, 2018

    @d33pak-s1ngh
    Author

    what this lines means "declare it as placeholder (the view will resize at runtime following labels dimensions)." because i am getting error of label size which says found nil while unwrapping optionals.

  2. d33pak-s1ngh commented on Jun 5, 2018

    @d33pak-s1ngh
    Author

    getting error in following function

    public func setLabelNumber(_ numberOfLabel: Int) { guard numberOfLabel > 0 else { return } labelContainer.spacing = labelSpacing > 0 ? labelSpacing : 10 self.numberOfLabel = numberOfLabel calculateViewWidth() addLabelsToStackView() }

  3. posix88 commented on Jun 5, 2018

    @posix88
    Owner

    hi @d33pak-s1ngh,

    about this issue:
    #1 (comment)

    you have to declare the width constraint as placeholder, you can do easily selecting you constraint and opening the size inspector tab on the right.

    I'm sorry but right now the library is designed to be loaded from a xib and not programatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions