I have a uitextview which become the first responder on viewload. but i want to change the position of the cursor of the uitextview at certain position in x for the first 2 line only.
-
mainy delegate methods of uitextview from google but none work @d4Rk – Gaurav Parmar Jun 20 '15 at 09:49
-
Can you show us some code, and whats not working? Or what you expect it to do. – d4Rk Jun 20 '15 at 10:05
-
I just want to do it like facebook screens for status update in android – Gaurav Parmar Jun 20 '15 at 10:57
2 Answers
Maybe you could use a UITextKit (a very good tutorial).
For example to have a rounded text you can use something like:
UIBezierPath* exclusionPath = [UIBezierPath bezierPathWithOvalInRect:yourTextView.bounds];
exclusionPath = [exclusionPath bezierPathByReversingPath];
yourTextView.textContainer.exclusionPaths = @[exclusionPath];

- 16,927
- 4
- 52
- 72
Have you tried following solutions ?
Controlling cursor position in a UITextField is complicated because so many abstractions are involved with input boxes and calculating positions. However, it's certainly possible. You can use the member function setSelectedTextRange
:
[input setSelectedTextRange:[input textRangeFromPosition:start toPosition:end]];
Here's a function which takes a range and selects the texts in that range. If you just want to place the cursor at a certain index, just use a range with length 0:
+ (void)selectTextForInput:(UITextField *)input atRange:(NSRange)range {
UITextPosition *start = [input positionFromPosition:[input beginningOfDocument]
offset:range.location];
UITextPosition *end = [input positionFromPosition:start
offset:range.length];
[input setSelectedTextRange:[input textRangeFromPosition:start toPosition:end]];
}
For example, to place the cursor at idx
in the UITextField input
:
[Helpers selectTextForInput:input
atRange:NSMakeRange(idx, 0)];
Source: https://stackoverflow.com/a/11532718/914111
Have not tested due to some busy so please let us know wether it is working or not (May have issue in IOS8.0)

- 1
- 1

- 2,862
- 17
- 27