ios - Textfield的rightView上有两个UIButtons
问题描述
我有一个问题,现在只显示一个按钮。我想要“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
}
解决方案
推荐阅读
- html - 悬停不适用于导航菜单中的嵌套元素
- java - 默认布局也显示在列表视图中
- node.js - 使用 Smart Websocket 客户端调试 socket.io
- python - 使用 selenium 和 python 自动发送测试用例的电子邮件测试报告
- android - 每次我按下结果按钮时应用程序都会崩溃
- django - AttributeError:模块'myapp'在Django中没有属性'startswith'
- javascript - 删除请求不起作用
- r - 将使用 mutate_ 创建的新变量分配给将在 dplyr 中作为字符串传递的名称
- shell - 如何在终端默认输出中添加“回声”
- typescript - Typescript“匿名”类型定义的正确名称是什么?