1

I want to indent part of the text in a UITextView

Original:

Paragraph Here:
Hello World this is just a test. 
Hello World this is just a test.
Hello World this is just a test

How do I make it show up like this

Paragraph Here:
    Hello World this is just a test. 
    Hello World this is just a test.
    Hello World this is just a test

I don't want to use spaces in the beggining because if the device is really small it will mess it all up

Junaid Javed
  • 25
  • 1
  • 10
  • This should help [https://stackoverflow.com/questions/25367502/create-space-at-the-beginning-of-a-uitextfield/27066764#27066764](https://stackoverflow.com/questions/25367502/create-space-at-the-beginning-of-a-uitextfield/27066764#27066764) – Tom Jul 20 '17 at 02:53
  • @Tom Can I add padding to part of the textView and not the whole thing – Junaid Javed Jul 20 '17 at 03:28

4 Answers4

1
var textMessage = "Paragraph Here:\nHello World this is just a test.\nHello World this is just a test.\nHello World this is just a test"
    textMessage = textMessage.replacingOccurrences(of: "\n", with: "\n\t")
    textView.text = textMessage

Try the above code. I hope it helps you.

KAREEM MAHAMMED
  • 1,675
  • 14
  • 38
1

For anyone else looking at this problem, I found a solution on this blog:

https://bendodson.com/weblog/2018/08/09/bulleted-lists-with-uilabel/

"The bulk of the heavy lifting is done by an NSParagraphStyle attribute called headIndent which adds a fixed amount of padding to all but the first line of a paragraph"

James
  • 130
  • 1
  • 6
0

Id use the "\t" to create a tab.

       let  string = "\tHello World this is just a test."
  • 1
    The text is gonna be like 20 sentences long and I want all of them to be tabbed. I can't do it at a certain place because it will be different depending on what device the person is using. – Junaid Javed Jul 20 '17 at 05:27
0

If you want each line in new row then use new line. Sample code

let textMessage = "Hello World this is just a test.\nHello World this is just a test.\nHello World this is just a test"
self.textView.text = textMessage

or if you want to leave a bit of space at the beginning of a UITextView then use it

 textView.layer.sublayerTransform = CATransform3DMakeTranslation(10, 0, 0)
Amrit Tiwari
  • 922
  • 7
  • 21
  • The text is gonna be like 20 sentences long and I want all of them to be tabbed. I can't do it at a certain place because it will be different depending on what device the person is using. – Junaid Javed Jul 20 '17 at 05:27