Adding the quot;Clearquot; Button to an iPhone UITextField(添加“清除iPhone UITextField 的按钮)
问题描述
如何在 UITextField 右侧添加用于清除文本的小X"按钮?我在 iPhone OS 2.2 SDK 的 Interface Builder 中找不到用于添加此子控件的属性.
How do you add that little "X" button on the right side of a UITextField that clears the text? I can't find an attribute for adding this sub-control in Interface Builder in the iPhone OS 2.2 SDK.
注意:在 Xcode 4.x 及更高版本(iPhone 3.0 SDK 及更高版本)中,您可以在 Interface Builder 中执行此操作.
Note: In Xcode 4.x and later (iPhone 3.0 SDK and later), you can do this in Interface Builder.
推荐答案
这个按钮是由 UITextField 类提供的内置叠加层,但在 iOS 2.2 SDK 中,没有'没有任何方法可以通过 Interface Builder 设置它.您必须以编程方式启用它.
This button is a built-in overlay that is provided by the UITextField class, but as of the iOS 2.2 SDK, there isn't any way to set it via Interface Builder. You have to enable it programmatically.
在某处添加这行代码(例如viewDidLoad):
Add this line of code somewhere (viewDidLoad, for example):
Objective-C
myUITextField.clearButtonMode = UITextFieldViewModeWhileEditing;
Swift 5.0
myUITextField.clearButtonMode = .whileEditing
这篇关于添加“清除"iPhone UITextField 的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:添加“清除"iPhone UITextField 的按钮
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
