我有一个问题,现在仅显示一个按钮。我想要“ Vergessen”吗?除非用户键入内容,否则将显示按钮。在编辑“眼睛”按钮时,应出现。现在只有其中一个显示出来,我不知道为什么。并有一种简单的方法可以更改“眼睛”按钮的大小吗?
func createForgetButton () {
let button = UIButton(type: .system)
button.setTitle("Vergessen?", for: .normal)
button.addTarget(self, action: #selector(self.vergessenTapped(_:)), for: .touchUpInside)
button.titleLabel?.font = UIFont(name: "Avenir Next", size: 19.0)
passwordTextField.rightView = button
passwordTextField.rightViewMode = .unlessEditing
}
func createTogglePassword () {
let button = UIButton(type: .system)
button.setBackgroundImage(UIImage(named: "eyeOpen"), for: .normal)
button.addTarget(self, action: #selector(togglePassword(_:)), for: .touchUpInside)
passwordTextField.rightView = button
passwordTextField.rightViewMode = .whileEditing
}
//我的文本字段的子类:
override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
let offset = -20
let width = 125
let height = 125
let x = Int(bounds.width) - width - offset
let y = offset
let rightViewBounds = CGRect(x: x, y: y, width: width, height: height)
return rightViewBounds
}