SwiftUI how to change font and color for email address in Text

457 Views Asked by At

If I didn't use verbatim with Text

Ex:

Text("Reach out to us on [email protected] for any queries!")
                    .foregroundColor(Color.white)
                    .font(Font.custom("Poppins-Regular", size: getFontSize(value: 16)))

Output:

Outpuy

And, if I used verbatim with

Text(verbatim: "Reach out to us on [email protected] for any queries!")

Ex:

Text(verbatim: "Reach out to us on [email protected] for any queries!")
                    .foregroundColor(Color.white)
                    .font(Font.custom("Poppins-Regular", size: getFontSize(value: 16)))

Output:

Output 2

Email clickable functionality not working if I used verbatim with Text()

I want to with email clickable.

clickable

2

There are 2 best solutions below

0
On

Try the below code It will help you:

  Text(.init("Reach out to us on [[email protected]]([email protected]) for any queries!"))
        .accentColor(.red)

here in the () round bracket, you have to write the link and in [] square bracket the respective text you want to see, here you want to show the email so in both brackets I wrote the email id modify as you want.

0
On

Jatin's solution also works if you just want to display an email address in your desired color: Text(.init("[email protected]")).font(.callout).accentColor(Color.white)