Learning iOS
SwiftUI’s Text’s Awesome tips
Magic of SwiftUI’s Text: Dive into the Tricks You Haven’t Tried Yet 😉
As I worked on some of my tasks, I tried writing something in text and discovered some amazing APIs that I would like to share with you. It’s beneficial to learn something new, even though there are modifiers available that you can apply to achieve the desired result.
Additionally, they are not so critical that you will use them again and again, but for someone who works extensively with Text APIs and their customization, they might be crucial. So let’s start 🎬
Most of the markup styles in text are understood by SwiftUI’s text. Once markup is applied, the outcomes are visible. Let’s give a couple of them a try that I know work. 🧐
Text("**Bold**")
//**String** will be bold
Text("*italics*")
Text("_This will also be italic_")
//**String** will be Italics
//_String_ will be Italics
Text("~~strikethrough~~")
//~~String~~ will be strikethrough
Text("[My Profile](https://medium.com/@verbalraj)")
.tint(.red)
//This will show My Profile text in to red color and if you run it in simulator it will open that link which you have mentioned in (link).
//[text to display](URL)
Text("This web site is using `your code here`")
Text("Here is the code ````for character in Aesop { println(character)}````")
//`string` will show your code in code font. i think its monospace font, correct me if i am wrong
//Also four backquotes will also give same effect: ```` code ````
It appears that SwiftUI's Text does not directly support other markdown features like headings, lists, photos, and code blocks (larger and multiline).
Try the above one and enjoy. Look at the outcome of everything we attempted below.
struct SwiftUIView: View {
var body: some View {
VStack(spacing: 20) {
Text("Hello, World! :[Next Topic](@next)")
Text("Hello, **World!**")
Text("[My Profile](https://medium.com/@verbalraj)")
.tint(.red)
Text("*italics*")
Text("_This will also be italic_")
Text("~~strikethrough~~")
Text("Here is the code ````for character in Aesop { println(character)}````")
}
}
}
and below is the output.
That concludes this little blog; feel free to test them all and let me know in the comments if they were useful.
And that’s it. Thank you for reading my post. I really appreciate your time. If you think it’s helpful, please clap or comment. And in the following one, I see you. 🙌