[swift]CosmicMind/材料文本占位符在左视图

标签: Xcode Swift
发布时间: 2016/12/26 21:43:00
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我使用CosmicMind / 材料框架正试图把图标放在左边的占位符,但地方持有人和图像覆盖每个其他的这里是我的代码

  Txtemail.placeholder = "EmailAdress"
    Txtemail.detail = "This EmailAdress is Not Valid"
    Txtemail.delegate = self
    Txtemail.placeholderNormalColor = Color.black
    Txtemail.placeholderActiveColor = Color.pink.base
    Txtemail.dividerNormalColor = Color.cyan.base
    Txtemail.tag=Example.Email.rawValue
    imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
    image = UIImage(named: "email.png");
    imageView.image = image;
    Txtemail.leftViewMode = UITextFieldViewMode.always
    Txtemail.leftView = imageView

这是结果

enter image description here

enter image description here

我到底做错了?在此先感谢

解决方法 1:

尝试不设置框架 CGRect(x: 0, y: 0, width: 20, height: 20)

试试这个︰

let leftView = UIImageView()
leftView.image = Icon.phone?.tint(with: Color.blue.base)

textField.leftView = leftView
textField.leftViewMode = .always

另外,尝试文本字段示例

官方微信
官方QQ群
31647020