ios - 如何快速读取 UITextInput 中的文本?

标签 ios swift uitextinput

我是 swift 的初学者。 我有

class A : UIViewController {
var textInput: UITextInput

init(textInput: UITextInput) {
    self.textInput = textInput
}

func getText() -> String() {
    /// Here I need to get the current text from textInput
}

}

如何获得?请帮忙。提前致谢!!!!

最佳答案

swift 3:

let start  = sender.beginningOfDocument
let end = sender.endOfDocument
let range = sender.textRange(from: start, to: end)!

let trimmedText = sender.text(in: range)
sender.replace(range, withText: "new text")

关于ios - 如何快速读取 UITextInput 中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33398022/

相关文章:

ios - iOS中的数据表

ios - View 不会在 ViewController 上呈现,以编程方式从不同的 Storyboard呈现

ios - 如何将选定的图像从 UIImagePicker 传递到 UIViewController

ios - 处理 iOS 键盘上的标记文本

ios - UITextView 观察文字变化

ios - 如何在iOS 10中更新每日本地通知消息?

iphone - UIPickerView 未返回正确的数据

arrays - 从字符串数组中过滤掉空字符串

ios - inputAssistantItem 和 inputAccessoryView 停止使用 ARC

objective-c - 仅支持一个 View 的不同方向 iOS 6