SwiftyFORM icon indicating copy to clipboard operation
SwiftyFORM copied to clipboard

Add Switch See/Hidden password property on PasswordText!

Open Vytek opened this issue 8 years ago • 5 comments

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.

Vytek avatar Jun 22 '16 10:06 Vytek

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

Does this work for you?

neoneye avatar Jun 22 '16 11:06 neoneye

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

Vytek avatar Jun 22 '16 13:06 Vytek

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
    }
}

neoneye avatar Jun 23 '16 06:06 neoneye

Thanks! I am trying...

Vytek avatar Jun 24 '16 11:06 Vytek

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

skyline75489 avatar Nov 03 '16 00:11 skyline75489