swift - textfield to a label atumatically?
问题描述
Is there any way in which I can send information from a textfield to a label automatically while writing for example if I have 2 texfield and 1 label
one by name and the other by last name
that when writing a single letter or a name this automatically appears in the label
some way to do this with de button
-> @IBAction func bt(_ sender: Any) { text =texfield!.text text = txfield!.text text.text = "\(textt!) \(texxt!)"
解决方案
您可以在 View Controller 的 viewDidLoad 方法中添加此文本更改侦听器。
yourTextField.addTarget(self, action: #selector(ViewController.textFieldDidChange(_:)), for: .editingChanged)
并将此功能添加到您的视图控制器
@objc func textFieldDidChange(_ textField: UITextField) {
yourLabel.text = textField.text
}
推荐阅读
- python - 我如何用一条最佳拟合线绘制我的线性回归模型?
- ios - 从 ViewController 到 UILabel 的 vcMenuLabel 出口无效。插座无法连接到重复内容
- kivy - 更改 Kivy 自定义按钮类中的文本
- java - 生成 JsonSchema 并使用 swagger 请求和响应模型进行验证
- reactjs - 如何验证多个输入字段以匹配特定条件?
- vuejs2 - 找不到模块'@vue/cli-plugin-unit-jest'
- python - 三重奏与 Asyncio 和正确启动/关闭循环
- azure - 在 Azure Monitor 中看不到负载均衡器的指标
- python - 无法安装 pyautogui。没有名为“pytweening”的模块
- java - 使用 Mocktio 从方法内部验证 startActivity 和 callBackListener