Reputation: 1108
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)
Upvotes: 44
Views: 36146
Reputation: 4733
Add the underline
modifier on the Text
view.
Text("Hello, world!")
.underline()
Upvotes: 109
Reputation: 10299
iOS 16 you can use the underline modifier, If you want anything more advanced like control its position and size, then you can use the background modifier, and in the bg you can set the height, offset, and color of the underline. Alternatively, you can also use the overlay modifier. Sample Code:
// Using background modifier
Text("FRANCE")
.foregroundColor(Color.white)
.background(
Color.white
.frame(height: 1) // underline's height
.offset(y: 14) // underline's y pos
)
//Using overlay modifier
Text("FRANCE")
.foregroundColor(Color.white)
.overlay(
Rectangle()
.fill(Color.white)
.frame(width: 64, height: 1)
, alignment: .bottom
)
Upvotes: 12
Reputation: 5053
You may use below like:
Text("Forget User ID")
.underline(true, color: .gray)
Upvotes: 6
Reputation: 1108
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)
Upvotes: 15