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

Add Switch See/Hidden password property on PasswordText! #20

Open
Vytek opened this issue Jun 22, 2016 · 5 comments
Open

Add Switch See/Hidden password property on PasswordText! #20

Vytek opened this issue Jun 22, 2016 · 5 comments

Comments

@Vytek
Copy link

Vytek commented Jun 22, 2016

Add Switch See/Hidden password property on PasswordText! See project: https://github.com/PiXeL16/PasswordTextField

How to modify item? Example? I would like to add this feature to your code.

@neoneye
Copy link
Owner

neoneye commented Jun 22, 2016

Maybe you can tweak CustomViewController.swift to create instances of the PasswordTextField.

Does this work for you?

@Vytek
Copy link
Author

Vytek commented Jun 22, 2016

It is not a XIB file. Only a TextField with a button at the end like:

         let hideShow = UIButton(type: UIButtonType.Custom) as UIButton
        hideShow.frame = CGRectMake(38, 38, 38, 38)
        hideShow.setImage(image_see, forState: .Normal)
        self.txtMasterPassword.rightView = hideShow
        self.txtMasterPassword.rightViewMode = .Always
        //http://stackoverflow.com/questions/7305538/uitextfield-with-secure-entry-always-getting-cleared-before-editing
        self.txtMasterPassword.clearsOnBeginEditing = false //Not working?
        self.txtMasterPassword.secureTextEntry = true
        hideShow.addTarget(self, action: #selector(LoginController.hideShow(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        self.view.addSubview(hideShow)

and the relative function:

func hideShow(Sender:UIButton!) {
        let hideShow: UIButton = (self.txtMasterPassword.rightView as! UIButton)
        if !self.txtMasterPassword.secureTextEntry {
            passwordBuffer = self.txtMasterPassword.text!
            self.txtMasterPassword.secureTextEntry = true
            hideShow.setImage(image_see, forState: .Normal)
            //http://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle
            self.txtMasterPassword.text = " ";
            self.txtMasterPassword.text = passwordBuffer
        } else {
            passwordBuffer = self.txtMasterPassword.text!
            self.txtMasterPassword.secureTextEntry = false
            //hideShow.setTitle("HIDE", forState: UIControlState.Normal)
            hideShow.setImage(image_nosee, forState: .Normal)
            //http://stackoverflow.com/questions/14220187/uitextfield-has-trailing-whitespace-after-securetextentry-toggle
            self.txtMasterPassword.text = " ";
            self.txtMasterPassword.text = passwordBuffer
        }
        //self.password.becomeFirstResponder() //Disabiltio per sicurezza?
    }

Had to modify your source? In: https://github.com/neoneye/SwiftyFORM/blob/master/Source/FormItems/TextFieldFormItem.swift

Thanks

@neoneye
Copy link
Owner

neoneye commented Jun 23, 2016

Perhaps do something like this. Untested

class PasswordTextCell: UITableViewCell {
    static func createCell() throws -> PasswordTextCell {
        let cell = PasswordTextCell()
        cell.setup()
        return cell
    }

    lazy var passwordField: UITextField = {
        let instance = UITextField()
        instance.secureTextEntry = true
        return instance
    }()

    lazy var hideShowButton: UIButton = {
        let instance = UIButton(type: .Custom)
        instance.frame = CGRectMake(38, 38, 38, 38)
        let image = UIImage(named: "hideShow")
        instance.setImage(image, forState: .Normal)
        instance.addTarget(self, action: #selector(PasswordTextCell.hideShow(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        return instance
    }()

    func setup() {
        addSubview(passwordField)
        addSubview(hideShowButton)
        passwordField.rightView = hideShowButton
        passwordField.rightViewMode = .Always
    }

    func hideShow(Sender:UIButton!) {
        // hide show
    }
}

@Vytek
Copy link
Author

Vytek commented Jun 24, 2016

Thanks! I am trying...

@skyline75489
Copy link
Contributor

I'd also love to see this feature. I'll try to implement this and see if I can came up with something.

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

3 participants