2

I'm trying to shift the text in my UITextView right by 20 pixels to create a text indent using the code below

[textview setContentInset:UIEdgeInsetsMake(0, 20, 0,-20)];

But this is cutting off the right hand side of my text as shown in the screenshot. Can any help me stop this happening please

enter image description here

totalitarian
  • 3,446
  • 6
  • 26
  • 50
  • Please see this SO answer: http://stackoverflow.com/a/12357042/312312 – Lefteris Jan 01 '13 at 20:41
  • I think that answer is for a TextField rather than a TextView? – totalitarian Jan 01 '13 at 21:13
  • Actually it's not working as it should with the solution I provided as it is not setting correctly the caret in the UITextView. I'm going to remove the solution. – Lefteris Jan 02 '13 at 12:43
  • Another issue is that the width of the text area doesn't expand when rotated horizontally – totalitarian Jan 02 '13 at 12:49
  • I didn't notice the issue with the caret – totalitarian Jan 02 '13 at 12:51
  • I would say that is far more simpler to place the UITextView with a transparent background over an UIImageView that has the notepad image and set the UITextView frame to the right instead... – Lefteris Jan 02 '13 at 13:16
  • The trouble with that is i draw the lines programayically. What was the issue with caret? It seems to work fine for me – totalitarian Jan 02 '13 at 13:19
  • 1
    You still can draw them in code. But add them to a separate view below the UITextView. The carret position was incorrect. Text was being added below the actual position of the cursor with the latest solution I did provide to overcome the issue when editing text – Lefteris Jan 02 '13 at 13:24
  • OK i'll look into drawing in subviews. Shame as the solution was so close. – totalitarian Jan 02 '13 at 13:28

2 Answers2

2

I think your edge insets are a bit off. Edge insets work towards the middle of the rectangle. For the right inset you should try 20 rather than -20.

[textview setContentInset:UIEdgeInsetsMake(0, 20, 0, 20)];
rickerbh
  • 9,019
  • 1
  • 28
  • 34
1

I couldn't find a solution to your problem even by subclassing UITextView and blocking setContentSize which seemed to be the problem.

[textview setContentInset:UIEdgeInsetsMake(0, 20, 0, rightInset)];

No matter what is the value of the rightInset the text is always clipped. Something is always redrawing text so that it fits the frame width of the text view. But I am wondering why do you need to set the inset? Can't you just set the background of the UITextView object to clear color and position it properly on your background view to get the illusion of indentation?

Mateusz
  • 314
  • 1
  • 5