Swift3:在用户输入上实时更新UiLabel [英] Swift3: Live UiLabel update on user input

查看:267
本文介绍了Swift3:在用户输入上实时更新UiLabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处搜索,似乎找不到实时更新标签的明确答案.

I've searched everywhere and can't seem to find a clear answer on updating a label in real-time.

如何在不使用按钮的情况下实时更新UILabel.例如,我有一个文本字段和连接到view controllerUIlabel.

How do i go about updating a UILabel (real-time) without the use of a button. For example, i have a text field and a UIlabel connected to the view controller.

用户一开始输入textfield,就会在UI标签上实时显示相同的文本.结果,这消除了使用按钮来更新标签的过程.我该怎么做?

As soon as the user starts typing in the textfield, the same text is being displayed in real time on the UI label. As a result,this eliminates the use of a button to update the label. How do i go about doing this?

推荐答案

使用委托方法:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    label.text = textField.text
    return true
}

这篇关于Swift3:在用户输入上实时更新UiLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆