我已经在 MaterialComponents on Github 打开了这个问题已经但似乎还没有答案。 问题是当我单击文本字段使其处于事件状态然后单击外部时,它工作正常但是当我重复这样做时,文本字段的占位符将始终位于顶部
这是问题的图片
代码如下:
@IBOutlet weak var textfieldFloating: MDCTextField!
let tf = MDCTextInputControllerOutlined()
override func viewDidLoad() {
super.viewDidLoad()
textfieldFloating.leftView = UIImageView(image: UIImage(named: "ic_lock_outline_white_18pt"))
textfieldFloating.leftViewMode = .always
textfieldFloating.placeholder = "Placeholder"
tf.textInput = textfieldFloating
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
最佳答案
我个人会选择 https://github.com/raulriera/TextFieldEffects CocoaPod 它有很多不同的样式供您使用,最重要的是它使用起来非常简单。
只需使用 pod init
创建一个 pod 文件
然后添加:
use_frameworks!
pod 'TextFieldEffects'
到您的 pod 并从终端使用 pod install
安装它。
使用方法:
该库是一个简单的插件,一旦您将子类设置为其中一种效果并将您的模块设置为 TextFieldEffects,您将能够在 Storyboard中看到所有 IBDesignable 设置。
您也可以根据需要在没有 Storyboard的情况下以编程方式使用它:
let textField = KaedeTextField(frame: textFieldFrame)
textField.placeholderColor = .darkGrayColor()
textField.foregroundColor = .lightGrayColor()
view.addSubView(textField)
关于ios - Swift:快速单击时 MaterialComponents TextFields 意外的占位符行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52584513/