Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI how to add an Underline to a Text View?

Tags:

ios

swift

swiftui

Is there a way to modify a Text view to have an underline? For example like this text below:

y͟o͟u͟r͟ t͟e͟x͟t͟

Text(Constants.chooseText)
    .font(Font.system(size: 26))
    .foregroundColor(Color.white)
    .padding(.bottom, 80)
like image 577
Kenny Kurochkin Avatar asked Jan 15 '20 12:01

Kenny Kurochkin


People also ask

How to make bold text in SwiftUI?

Add double asterisks (**) arroud the text/characters to make it bold.

How do you underline labels in swift storyboard?

Here is the solution in storyboard: Open the Attribute Inspector (make sure label is selected), Change the dropdown value from 'Plain' to 'Attributed'. Now a a small text editor will be visible under the font of the label. Select the text of the label, right click and change the font to 'underline'.

Is text a view in SwiftUI?

Text in SwiftUI is a view that lets you display one or more lines of text. This is suitable for read-only information that's not editable. To display a line of text, you initialize Text and set a String value.


Video Answer


2 Answers

Add the underline modifier, on the Text View

        Text("Hello, world!")
            .underline()
like image 93
byaruhaf Avatar answered Oct 16 '22 20:10

byaruhaf


UPDATE adding underline() as the first modifier solved the issue.

Text(Constants.chooseText)
    .underline()
    .font(Font.system(size: 26))
    .foregroundColor(Color.white)
    .padding(.bottom, 80)
like image 22
Kenny Kurochkin Avatar answered Oct 16 '22 21:10

Kenny Kurochkin