How to Add Underline Text in iOS SwiftUI
In this blog post, we’re focusing on a commonly used tool for emphasizing content within an application – underlining text in SwiftUI. Whether it’s for accentuating headers, highlighting hyperlinks, or drawing attention to certain pieces of information, underlined text can significantly improve the user interface and experience.
Basics: Underlining Text
In SwiftUI, the .underline()
modifier is used to underline text. It’s simple, straightforward, and efficient. Here’s an example:
Text("Hello, SwiftUI!")
.underline()
In this example, the text “Hello, SwiftUI!” will be presented with an underline.
![underline text in swiftui](https://codingwithrashid.com/wp-content/uploads/2023/07/swiftui-underline-text--509x1024.png)
Combine with Other Modifiers
The .underline()
modifier can be combined with other SwiftUI text modifiers to create more personalized and dynamic text views:
Text("Hello, SwiftUI!")
.underline()
.bold()
.foregroundColor(.blue)
In this example, the text “Hello, SwiftUI!” is underlined, bolded, and presented in blue color.
![swiftui underlined text](https://codingwithrashid.com/wp-content/uploads/2023/07/underline-text-in-swiftui-499x1024.png)
Adding underlines to text in SwiftUI is an easy yet powerful way to emphasize and highlight content in your app. Its easy-to-use and composable nature still provides a host of possibilities for underlined text presentation.