首页 > 解决方案 > MDCTextField rightView 属性在 iOS 13 上损坏

问题描述

我不能再在 iOS 13 上使用该rightView属性MDCTextField。我是唯一一个对此有问题的人吗?

右视图宽度覆盖整个文本字段:防止用户交互并隐藏 textView 内容。

当我从 切换MDCTextField到时没有问题UITextField

标签: iosswiftios13material-components

解决方案


宽度 constraint添加到rightView/ leftView

不要忘记设置translatesAutoresizingMaskIntoConstraints = false

rightView.translatesAutoresizingMaskIntoConstraints = false
rightView.widthAnchor.constraint(equalToConstant: <#NeededWidth#>).isActive = true
// This is enough to make it act like before but you can set other missing constraints like height to suppress layout warnings and prevent further issues.
// rightView.widthAnchor.constraint(equalToConstant: <#HeightOfTheTextField#>).isActive = true

您可能会在 consule 中注意到一些自动布局警告,因为您没有为rightView/设置缺少的约束leftView。所以添加缺少的约束或干脆忽略那些。

请注意,如果rightView/leftView是某种StackView,请尝试将其放在 a 中view,然后添加此视图。


推荐阅读