Junaid Javed
Junaid Javed

Reputation: 25

How do I indent part of the text in a UITextView

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

Upvotes: 1

Views: 3406

Answers (4)

James
James

Reputation: 130

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"

Upvotes: 1

KAREEM MAHAMMED
KAREEM MAHAMMED

Reputation: 1695

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.

Upvotes: 1

Amrit Tiwari
Amrit Tiwari

Reputation: 990

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)

Upvotes: 0

Mackenzie Norman
Mackenzie Norman

Reputation: 1

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

       let  string = "\tHello World this is just a test."

Upvotes: 0

Related Questions