📦Text
⭐ 基本語法
// ⭐️ "string" 並非單純字串,它其實當作 "localization key"
Text("string")
// ⭐️ 設定小數位數
Text("\(scale, specifier: "%.2f")" ) // ⭐️ 設定小數位數(Slider 常用)
// 小數位數 ↴
Text("scale:\(scale, specifier: "%0.2f")") // 兩位小數
.font(.system(.body, design: .monospaced)) // ⭐️ 使用等寬字體// ⭐️ 多行對齊
Text("first line\nsecond line\nthird line")
.multilineTextAlignment(.center) // ⭐️ 還有 .leading, .trailing
SwiftUI ⟩ Text Input and Output ⟩
Font ⟩
system(_:design:weight:):specifies style, design, and weight.
system(size:weight:design:):specifies a system font.
Foundation ⟩ Strings and Text ⟩ AttributedString (struct)
Text uses only a subset of the attributes defined in AttributeScopes.FoundationAttributes.
Textrenders allInlinePresentationIntentattributes except forlineBreakandsoftBreak.It also renders the
linkattribute as a clickable link.Textignores any other Foundation-defined attributes in an attributed string.
Five Stars ⟩ SwiftUI patterns: passing & accepting views - inline image
AppCoda ⟩ Learn SwiftUI ⟩ Working with Text ⭐️
Paul ⟩ How to combine text views together - Text
+Text.Swift Wombat ⟩ How to style Text view in SwiftUI ⭐️
問:如何幫文字設定各種格式❓如何排版文字❓
Last updated
Was this helpful?