uitextrange

UITextPosition in UITextField

不打扰是莪最后的温柔 提交于 2019-12-12 08:23:00
问题 Is there any way for me to get at a UITextField's current caret position through the text field's UITextRange object? Is the UITextRange returned by UITextField even of any use? The public interface for UITextPosition does not have any visible members. 回答1: I was facing the same problem last night. It turns out you have to use offsetFromPosition on the UITextField to get the relative position of the "start" of the selected range to work out the position. e.g. // Get the selected text range

UITextInput: selectedTextRange vs. markedTextRange?

妖精的绣舞 提交于 2019-12-06 00:24:00
问题 Ok, so I know Apple's UITextInput protocol requires the two UITextRange properties selectedTextRange and markedTextRange and the documentation says that selectedTextRange is a subrange of markedTextRange which is an uncomfirmed text range by the user yatta yatta. That still doesn't make some things clear to me regarding how I ought to implement the two text ranges differently. Could someone visually explain to me the difference between selectedTextRange and markedTextRange ? I know that when

UITextInput: selectedTextRange vs. markedTextRange?

对着背影说爱祢 提交于 2019-12-04 06:08:17
Ok, so I know Apple's UITextInput protocol requires the two UITextRange properties selectedTextRange and markedTextRange and the documentation says that selectedTextRange is a subrange of markedTextRange which is an uncomfirmed text range by the user yatta yatta. That still doesn't make some things clear to me regarding how I ought to implement the two text ranges differently. Could someone visually explain to me the difference between selectedTextRange and markedTextRange ? I know that when the length of selectedTextRange is 0 it indicates a blinking caret at selectedTextRange 's location .

UITextPosition in UITextField

北战南征 提交于 2019-12-04 00:51:53
Is there any way for me to get at a UITextField's current caret position through the text field's UITextRange object? Is the UITextRange returned by UITextField even of any use? The public interface for UITextPosition does not have any visible members. I was facing the same problem last night. It turns out you have to use offsetFromPosition on the UITextField to get the relative position of the "start" of the selected range to work out the position. e.g. // Get the selected text range UITextRange *selectedRange = [self selectedTextRange]; //Calculate the existing position, relative to the

Convert selectedTextRange UITextRange to NSRange

不打扰是莪最后的温柔 提交于 2019-11-28 22:26:47
问题 How can I convert a UITextRange object to an NSRange ? I've seen plenty of SO posts about going the other direction but that's the opposite of what I need. I'm using the UITextRange selectedTextRange which is a property of a UITextView . It returns a UITextRange but I need a range. 回答1: You need something like this: - (NSRange) selectedRangeInTextView:(UITextView*)textView { UITextPosition* beginning = textView.beginningOfDocument; UITextRange* selectedRange = textView.selectedTextRange;

Control cursor position in UITextField

不想你离开。 提交于 2019-11-26 09:22:55
问题 I have a UITextField that I\'m forcing formatting on by modifying the text inside the change notification handler. This works great (once I solved the reentrancy issues) but leaves me with one more nagging problem. If the user moves the cursor someplace other than the end of the string then my formatting change moves it to the end of the string. This means users cannot insert more than one character at a time into the middle of the text field. Is there a way to remember and then reset the