Answers for "how to new line in uilabel in swift"

0

next line swift

//I'll try to explain how to make new lines as many ways as possible
//Since you might not have defined in what context do you want the new line to be in

//In native swift context

//You could use \n or \r\n

print("Hello \n world!")

var sentence = "One word \n another word"
print(sentence)

//Or you can use triple quotation """ (text) """

print(""" Multi Lines
      	  Are fun this way""")

//In UIKit context

//If you wish to edit it from the attributes tab:
//https://stackoverflow.com/questions/1121358/uilabel-wordwrap-text

//If you wish to edit it code-wise:
//https://www.hackingwithswift.com/articles/113/nsattributedstring-by-example
//This might help


//In SwiftUI Context

//You can add \n to create a line break

//Some examples:

Text("New \n Line \n after \n each \n word")

//Or use the triple quotation syntax """ (text) """

Text("""
     New
     Line
     After
     Every
     Word
     """)

//For TextField and TextEditors and such, it is best to use the multiLineTextAlignment modifier
Posted by: Guest on August-14-2021

Code answers related to "how to new line in uilabel in swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language