簡體   English   中英

SwiftUI 如何給文本視圖添加下划線?

[英]SwiftUI how to add an Underline to a Text View?

有沒有辦法修改文本視圖以具有下划線? 例如像下面這樣的文字:

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

Text(Constants.chooseText)
    .font(Font.system(size: 26))
    .foregroundColor(Color.white)
    .padding(.bottom, 80)

在文本視圖上添加下划線修飾符

        Text("Hello, world!")
            .underline()

UPDATE 添加 underline() 作為第一個修飾符解決了這個問題。

Text(Constants.chooseText)
    .underline()
    .font(Font.system(size: 26))
    .foregroundColor(Color.white)
    .padding(.bottom, 80)

iOS 16您可以設置背景,在背景中您可以設置高度偏移量和下划線顏色 示例代碼:

Text("Gurjinder Singh")
          .font(.largeTitle)
          .fontWeight(.heavy)
          .background(
             Color.accentColor
                   .frame(height: 6) // underline's height
                   .offset(y: 24) // underline's y pos
           )

Output

在此處輸入圖像描述

您可以像下面這樣使用:

Text("Forget User ID")
     .underline(true, color: .gray)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM