我可以动态更改UITextField的属性UIReturnKeyType吗? [英] Can I change property UIReturnKeyType of UITextField dynamically?

查看:107
本文介绍了我可以动态更改UITextField的属性UIReturnKeyType吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以将UITextField的这个属性设置为Send,Search,Go等:

we can set this property of UITextField to "Send", "Search", "Go", etc.:

@property(nonatomic) UIReturnKeyType returnKeyType

但是在使用UITextField时设置它根本不会改变。

But setting it while using the UITextField doesn't change at all.

我想要这样的行为:
当UITextField为空时,让returnKeyType为Return,否则让returnKeyType为Send。

I want this behavior: When UITextField is empty, let returnKeyType be "Return", otherwise let returnKeyType be "Send".

推荐答案

通常在显示键盘时会检查 returnKeyType 和其他属性,但不会被监控供以后更新。在更改 returnKeyType 之后,尝试在文本字段上调用 reloadInputViews ,这应该指示它刷新键盘设置。

Normally the returnKeyType and other properties are checked when the keyboard is displayed, but are not monitored for later updates. Try calling reloadInputViews on the text field after changing the returnKeyType, that should instruct it to refresh the keyboard settings.

这篇关于我可以动态更改UITextField的属性UIReturnKeyType吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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