๐ฆText
Last updated
Last updated
โญ ๅบๆฌ่ชๆณ
// "string" ไธฆ้ๅฎ็ดๅญไธฒ๏ผๅฎๅ
ถๅฏฆ็ถไฝ "localization key"
Text("string")
Text
uses only a subset of the attributes defined in AttributeScopes.FoundationAttributes
.
Text
renders all InlinePresentationIntent
attributes except for lineBreak
and softBreak
.
It also renders the link
attribute as a clickable link.
Text
ignores any other Foundation-defined attributes in an attributed string.
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading, spacing: 20) {
texts
Color.secondary.frame(height: 0.5)
textWithBG
}
.padding(40)
}
}
extension ContentView {
/// โญ text with background is NO MORE a `Text`โโโ
var textWithBG: some View {
HStack {
Text("โ ๏ธ")
Text(" .background ").background(Color.pink)
Text(" is ")
+ Text("NO MORE").bold().foregroundColor(.pink)
+ Text(" a `Text`โ")
}
}
/// texts in different styles
var texts: some View {
[
Text(".bold").bold(),
Text(".italic").italic(),
Text(".foregroundColor").foregroundColor(.green),
Text(".font(.title)").font(.title),
Text("\n.fontWeight(.heavy)").fontWeight(.heavy),
Text(".font(.system(size:40))").font(.system(size: 40)),
Text("\n.strikethrough").strikethrough(),
Text(".strikethrough(true, color: .red)").strikethrough(true, color: .red),
Text("\n.underline").underline(),
Text(".underline(true, color: .blue)").underline(true, color: .blue),
Text(".baseline")
+ Text("Offset(10)").baselineOffset(10).font(.caption),
Text("\n.kerning .kerning .kerning").kerning(8),
Text("\n.tracking (letter-spacing)").tracking(8),
Text("\nโญ๏ธ inline system image: Five ")
+ Text(Image(systemName: "star.circle.fill")).foregroundColor(.yellow)
+ Text(" Stars"),
Text("\nโญ๏ธ markdown: Go for [apple.com](https://apple.com)"),
]
.reduce(into: Text("normal")) { result, text in
result = result + Text(" ") + text
}
.lineSpacing(10)
.foregroundColor(.secondary)
}
}
Swift.Equatable
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 โญ๏ธ
ๅ๏ผๅฆไฝๅนซๆๅญ่จญๅฎๅ็จฎๆ ผๅผโๅฆไฝๆ็ๆๅญโ