将占位符添加到UITextField,如何以编程方式快速设置占位符文本? [英] Add Placeholder to UITextField, how to set the placeholder text programmatically in swift?

查看:96
本文介绍了将占位符添加到UITextField,如何以编程方式快速设置占位符文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从数据库中提取一个电话号码,当用户开始在文本字段中进行编辑以更改该电话号码时,我想使用数据库中当前的号码作为占位符.由于此信息随每个用户而变化,因此如何以编程方式快速设置它?

I'm pulling out a phone number from a database, and when the user begins editing in the text field to change that phone number I'd like to use the number I currently have in the database as the placeholder. Since this information changes with each user, how can I set it programmatically in swift?

推荐答案

您需要先从数据库中获取电话号码(将其转换为String),然后将textFieldplaceholder设置为该String,像这样

You need to get the phone number from your database first (convert them to String), then you set placeholder of your textField to that String, like so

 textField.placeholder = phoneNumberString

这篇关于将占位符添加到UITextField,如何以编程方式快速设置占位符文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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