Hello friend,
Welcome back to Learning SwiftUI. This is post number 13 and this will probably be my shortest post so far as I have been spending my time at the hospital since wednesday. But I thought I could share a quick tip with you this week. This was something that I picked up from Youtube (link at the end of this post) and I thought it was a really neat way to embed a link in your text view.
Normally I set up a link like this:
struct TextEmbedLink: View {
var body: some View {
VStack(spacing: 15) {
Text("Click the link to Apple's webpage below for mor information:")
.multilineTextAlignment(.center)
Link("Apple Webpage", destination: URL(string: "https://www.apple.com")!)
}
.frame(width: 300)
}
}
Want to learn more about SwiftUI animations?
I created a book for anyone new to SwiftUI that wants to develop their SwiftUI animation skills. The book cover the basics and more advance techniques to animating objects and views in SwiftUI. You can check it out by clicking the link below:
Learning SwiftUI Animations - The Beginner Roadtrip
In this scenario, we set up a VStack with a text view and a link. But another way you could do this is to embed the link inside the text view. Here is how you do that:
struct TextEmbeddLink: View {
var body: some View {
VStack(spacing: 25) {
Text("Click the link to Apple's webpage below for mor information:")
.multilineTextAlignment(.center)
Link("Apple Webpage", destination: URL(string: "https://www.apple.com")!)
Text("Hello SwiftUI learner, you want to learn more about SwiftUI? Then visit [My Substack](https://learningswiftui.substack.com)! for even more tips and tricks.")
}
.frame(width: 300)
}
}
This is a very neat way to make a link appear inside your text view. That was it for this week. Have you ever used this way before? Let me know in the comments!
And as promised, here is the link to the YouTube video where I learned this neat little trick. My suggestion is to watch the whole thing as many neat little tricks are discussed here.
Have a nice day!
Mr SwiftUI