【问题标题】:button image is not show in rightView of UItextfield按钮图像未显示在 UItextfield 的 rightView 中
【发布时间】:2019-09-11 23:38:42
【问题描述】:

我创建了一个按钮图像,并使用 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
}

图片

【问题讨论】:

  • 因为你把它放在“rightView”里面,所以按钮的x和y应该是0,因为它已经相对于右视图了。
  • 已修复,谢谢
  • 你能把你的评论转换成答案吗
  • 添加为答案,祝你好运:)

标签: ios swift button uitextfield


【解决方案1】:

因为你把它放在“rightView”里面。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-07
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多