`UITextRange` objects represent a range of characters in a text container in Apple's `UIKit` framework, such as `UITextField` or `UITextView`.
Questions tagged [uitextrange]
20 questions
52
votes
7 answers
Control cursor position in UITextField
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…

Jeremy
- 849
- 1
- 7
- 11
32
votes
4 answers
Convert selectedTextRange UITextRange to NSRange
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…

Milo
- 5,041
- 7
- 33
- 59
16
votes
2 answers
UITextPosition in UITextField
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…

futureelite7
- 11,462
- 10
- 53
- 87
13
votes
4 answers
How to get a selected range of text from a UITextView or UITextField
I am trying to get the selected range of text from a UITextView (and or UITextField) so that I can edit the selected text, or modify an attributed string. The method below is triggered when I make a selection, but the code in the method returns null…

OWolf
- 5,012
- 15
- 58
- 93
9
votes
2 answers
Objective C how to get the numeric value of a UITextPosition
I need to get the numeric value of the start and end of a UIText range. So far I can only print out the description as a string.
From looking at the selectedTextRange, I take it that it is maybe a struct? How do I get an element of a…

OWolf
- 5,012
- 15
- 58
- 93
8
votes
1 answer
UITextInput: selectedTextRange vs. markedTextRange?
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…

rolling_codes
- 15,174
- 22
- 76
- 112
3
votes
1 answer
UITextInput returns nil position only in iOS 9
I am trying to get the rect of a specific range (UITextRange).
The problem is that the code works fine with iOS 10 , and I am getting
the range and rect. Unfortunately with iOS 9 the line :
if let rangeStart = textInput.position(from:…

PoolHallJunkie
- 1,345
- 14
- 33
3
votes
1 answer
How to get offset from start of line of UITextRange.start
I have an UITextView which can have multiple lines. All I'm interested in is the position of the cursor on a certain line (where it doesn't matter whether first, second, third line etc.).
I've been logging UITextRange.start which gives me exactly…

n.evermind
- 11,944
- 19
- 78
- 122
2
votes
1 answer
Select whole text of UITextView using Swift
I tried to do this the same way as I'm doing it with a UITextField:
textView.selectedTextRange = textView.textRange(from: textView.beginningOfDocument, to: textView.endOfDocument)
What am I doing wrong?

l30c0d35
- 777
- 1
- 8
- 32
2
votes
0 answers
CGRect of firstRectForRange method in UITextView returns wrong frame position in iOS 9
Running the below code in iPod 5 / iPad with iOS 8 and iOS 9 gives the below output
CGRect textViewFrame;
if(IS_IPHONE_5)
textViewFrame = CGRectMake(0.0f, 64.0f, 320.0f, 390.0f);
else
textViewFrame = CGRectMake(0.0f, 64.0f, 320.0f,…

Kenshin
- 1,030
- 2
- 12
- 41
2
votes
1 answer
Is it possible to create UITextRange manually for first character?
Is it possible to instantiate UITextRange and for first character of UITextField?
i need to access to rect of UITextField 's first character, can anyone help me?
Thanks in advance

Mojtaba
- 514
- 9
- 19
2
votes
2 answers
How to get the rects from UITextRange in earlier iOS version than iOS 6.0
I wanna get the all rects from UITextRange. you know, if UITextView line wrap, the UITextRange will be represented by more than 1 CGRect. in iOS 6.0, there is a method as "selectionRectsForRange:", so you can get the all CGRects. But in older…

Oliver
- 46
- 5
1
vote
1 answer
Move Cursor to Beginning of Prepopulated Textview On Load in Objective-C
Upon a View Controller loading from code where a UITextView is prepopulated with some text, I would like the cursor to be at the beginning of the text not at the end.
The following code however is having no effect. The cursor still appears at the…

Arjun321
- 89
- 1
- 8
1
vote
1 answer
Remove html content without losing formatting, But black pdf is genrated
Pdf is genrating but its is coming blank ,I want to get a html content data in pdf without losing formatting, so i tried this code in this only blank pdf is genrating
package config;
import com.lowagie.text.DocumentException;
import…

Amigo
- 21
- 1
- 6
1
vote
0 answers
How can we implement UITextPosition and UITextRange subclasses in discrete files of their own?
When creating custom UIView or UIScrollView subclasses for use with Core Text, how can we implement UITextPosition and UITextRange subclasses in discrete files of their own?
We need these to implement UITextInput, UITextInputTraits and UIKeyInput…

uchuugaka
- 12,679
- 6
- 37
- 55