1

I have a UITextView that has a fixed width and height. I pre-populate the entire textfield with blanks.

I would like to insert a character with the push of a button that will erase the last blank character, insert my string character and then place the cursor at the beginning of the newly inserted string. I am trying to achieve inserting special fonts right to left and bottom to top.

It is working with the first button push and on the second button push the new value is inserted in the correct position to the left, however, the cursor will not move to the left after the second button push, it remains to the right after the second string insert.

Here is my code...

-(IBAction)chartP:(id)sender {
    NSRange currentRange = myChart.selectedRange;
    if (currentRange.length == 0) {
        currentRange.location--;
        currentRange.length++;
    }
    myChart.text = [myChart.text stringByReplacingCharactersInRange:currentRange
        withString:[NSString string]];
    currentRange.length = 0;
    myChart.selectedRange = currentRange;

    myChart.text = [myChart.text stringByAppendingString:@"p"];

    myChart.selectedRange = NSMakeRange(myChart.selectedRange.location -1, 0);
}

Can someone assist me with what I am missing here to continually increment to the left with my string inserts?

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
Dan
  • 398
  • 4
  • 15

2 Answers2

2

How about flipping the text area:

myChart.transform = CGAffineTransformMakeScale(-1,-1);
CactusPCJack
  • 459
  • 5
  • 18
1

It sounds like you are trying to implement right-to-left text direction by faking it. Why not do the real thing?

Here's a question that covers the topic: Change the UITextView Text Direction

If you need bottom-to-top entry, and you have the ability to use a custom font, perhaps you can apply a transformation to the UITextView and y-flip it. Look at the transform property of UIView. (Things like the text selection loupe may break, but it's worth a try.)

Community
  • 1
  • 1
benzado
  • 82,288
  • 22
  • 110
  • 138
  • I tried that solution before posting, it does right to left but not bottom to top, that is why I am trying to fake it. – Dan Feb 13 '12 at 17:58