【发布时间】:2017-03-20 15:00:21
【问题描述】:
我正在尝试获取特定范围的矩形 (UITextRange)。
问题是代码可以正常工作 iOS 10 ,我得到了
范围和矩形。不幸的是iOS 9这条线:
if let rangeStart = textInput.position(from: textInput.beginningOfDocument, offset: location)
返回nil
let location = self.textView.firstRect(for: range)
extension NSRange {
func toTextRange(textInput:UITextInput) -> UITextRange? {
if let rangeStart = textInput.position(from: textInput.beginningOfDocument, offset: location),
let rangeEnd = textInput.position(from: rangeStart, offset: length) {
return textInput.textRange(from: rangeStart, to: rangeEnd)
}
return nil
}
}
【问题讨论】:
标签: ios swift uitextview uitextinput uitextrange