我已经创建了一个按钮图像,并使用Sa wift将其放在UITextField“rightView”的密码上。我想创建切换按钮隐藏/显示密码字段中的安全文本。右视图中显示的图像。
代码:
func passwordToggleButton(){
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "hidePassword"), for: .normal)
button.imageEdgeInsets = UIEdgeInsets(top: 0, left: -16, bottom: 0, right: 0)
button.frame = CGRect(x: CGFloat(txtfPassword.frame.size.width - 25), y: CGFloat(5), width: CGFloat(25), height: CGFloat(25))
button.backgroundColor = UIColor.white
button.addTarget(self, action: #selector(self.togglePassword), for: .touchUpInside)
txtfPassword.rightView = button
txtfPassword.rightViewMode = .always
}图像

发布于 2019-04-23 04:33:46
因为你把它放在“rightView”里面。
框架的X和Y坐标成为相对于它的坐标。
所以你应该把它们改成0,0
https://stackoverflow.com/questions/55800140
复制相似问题