I have an app that has a text field where I enter text though code. Here's an example:
var text = ["This is the text that appears in the Text View."]
I want to know how I can add paragraph spaces in the Text View through the code. Such as the text view says this:
Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
But, I want to add a paragraph space like this:
Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Could you help me with this?
iOS app using Swift 3 and Xcode 8
If you are using static text in the app, you can simply use the
newline
characters along with the text"\n"
. If it is dynamic / entered by user, then also you can check for new line character intextView delegate method
and can add addition new line characters as you want.Also, as in the comment above you can use
NSParagraphStyle
and can setparagraphSpacing
(The space after the end of the paragraph) andparagraphSpacingBefore
(The distance between the paragraph’s top and the beginning of its text content) properties to get desired spacing.