Ronit Vasoya
Ronit Vasoya

Reputation: 21

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

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

Upvotes: 2

Views: 864

Answers (3)

Shakeel Ahmed
Shakeel Ahmed

Reputation: 6023

SwiftUI easy solution

 Text("[email protected]")
 .accentColor(.black)
 .multilineTextAlignment(.leading)

Upvotes: 1

Wilson Toussaint Jr.
Wilson Toussaint Jr.

Reputation: 31

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)

Upvotes: 0

Jatin Bhuva
Jatin Bhuva

Reputation: 1874

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.

Upvotes: 1

Related Questions