gpt4 book ai didi

ios - 按钮图像未显示在 UItextfield 的 rightView 中

转载 作者:行者123 更新时间:2023-11-28 13:42:54 28 4
gpt4 key购买 nike

我创建了一个按钮图像并使用 Sa wift 将其放置在 UITextField“密码”的 rightView 上。我想在密码字段中创建切换按钮隐藏/显示安全文本。右侧 View 中显示的图像。

代码:

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
}

图片

enter image description here

最佳答案

因为您将它放在“rightView”中。

框架的 X 和 Y 坐标相对于它。

所以你应该把它们改成 0, 0

关于ios - 按钮图像未显示在 UItextfield 的 rightView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55800140/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com