ios - Swift:快速单击时 MaterialComponents TextFields 意外的占位符行为

标签 ios swift material-components material-components-ios

我已经在 MaterialComponents on Github 打开了这个问题已经但似乎还没有答案。 问题是当我单击文本字段使其处于事件状态然后单击外部时,它工作正常但是当我重复这样做时,文本字段的占位符将始终位于顶部

这是问题的图片

当文本域加载时: enter image description here

当文本框激活时: enter image description here

当我们重复点击文本域然后再次点击外部时,它看起来像这样 enter image description here

代码如下:

@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/

相关文章:

android - 使用 TextInputLayout.OutlinedBox 样式的 Material 设计 Spinner

android - Theme.MaterialComponents 不会更改对话框标题的字体

Android Chip Custom Height Or Padding - Chipgroup 间距

iphone - 在工具栏中单击 "Select All"按钮时如何插入复选标记?

swift - 如何在 Swift 中使用 UILongPressGestureRecognizer 通过标签属性传递 indexPath.row?

ios - 如果我在同一 View 上有两个 ImageView ,如何区分哪个 UIImagePickerController 调用 func didCancel?

iOS、AdobeCreativeSDK C 到 Swift

ios - 从图像中捕获文本 - SwiftUI

ios:异步请求后重新加载 UIPickerView

ios - 为什么要为 iOS 项目创建动态框架?