【问题标题】:How is it possible to add icons to my UItextfield?如何将图标添加到我的 UItextfield?
【发布时间】:2018-10-01 05:39:50
【问题描述】:

非常感谢您的帮助:),还有什么方法可以在输入用户名或密码时使下划线改变颜色?

【问题讨论】:

标签: swift4 xcode9


【解决方案1】:

尝试添加以下代码:

    let iconWidth = 20;
    let iconHeight = 20;

    //Define the imageView
    let imageView = UIImageView();
    let imageEmail = UIImage(named: "xyz.png");
    imageView.image = imageEmail;

    // set frame on image before adding it to the uitextfield
    imageView.frame = CGRect(x: 5, y: 5, width: iconWidth, height: iconHeight)
    textField.leftViewMode = UITextFieldViewMode.Always
    textField.leftView = imageView

【讨论】:

    【解决方案2】:

    您可以将 UIImageView 用作 UITextField 中的子视图

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 1970-01-01
      • 2014-04-15
      相关资源
      最近更新 更多