Open Vytek opened 8 years ago
Maybe you can tweak CustomViewController.swift to create instances of the PasswordTextField.
Does this work for you?
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
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
}
}
Thanks! I am trying...
I'd also love to see this feature. I'll try to implement this and see if I can came up with something.
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.