ios - 如何在 Swift 中使用“MDCOutlinedTextField”
问题描述
我需要如下图所示的文本字段
所以我使用material-components-ios框架,为此我在情节提要中添加了文本字段并将其类名MDCTextField
和代码
import UIKit
import MaterialComponents
class LoginVC: UIViewController {
@IBOutlet weak var emailTF: MDCTextField!
var textFieldControllerFloating: MDCTextInputControllerOutlined?
override func viewDidLoad() {
super.viewDidLoad()
// setupEditText()
textFieldControllerFloating = MDCTextInputControllerOutlined(textInput: emailTF)
textFieldControllerFloating?.activeColor = UIColor.lightGray
textFieldControllerFloating?.floatingPlaceholderActiveColor = UIColor.green
textFieldControllerFloating?.normalColor = UIColor.lightGray
textFieldControllerFloating?.inlinePlaceholderColor = UIColor.lightGray
}
这段代码 o/p 完美但显示警告
警告:
'MDCTextField' 已弃用:MDCTextField 及其关联的类已弃用。请改用 TextControls。
所以我在这里添加了另一个框架TextControlspod 'MaterialComponents/TextControls+OutlinedTextFields'
我在 stroyboard中添加和添加了文本字段,并将其类赋予MDCOutlinedTextField
并添加到代码下方
import UIKit
import MaterialComponents.MaterialTextControls_OutlinedTextFields
class LoginVC: UIViewController {
@IBOutlet weak var emailTF: MDCOutlinedTextField!
@IBOutlet weak var passwordTF: MDCOutlinedTextField!
}
}
但是o / p如下所示:没有浮动占位符文本和小高度,为什么?,我错在哪里..如何获得高度为50和浮动占位符边框的文本字段,如上图,请帮忙。
编辑:我需要这样的密码文本字段的眼睛按钮怎么办MDCOutlinedTextField
?
解决方案
根据示例尝试设置label.text
这样的属性
textField.label.text = "Phone number"
至于文本字段高度,您可以使用 Interface Builder 中的约束来设置它
推荐阅读
- c++ - 运行后 Eclipse 不会“释放”.exe
- c# - 如何恢复最小化/隐藏窗口?
- julia - LoadError:InitError:在新环境中预编译时
- javascript - 如何在网页上使用 CefSharp 写入电子邮件和密码值
- php - 三点菜单 PHP HTML
- python - TemplateDoesNotExist at /poll/1/ -Django 教程
- python - 滑动窗口 - 测量每个循环窗口上的观察长度
- python - 如何使用 groupby 可视化数据
- sql - MS SQL LAST_VALUE() 排序依据
- git - 基于共享功能分支的 git merge vs rebase