SwiftUI基础控件篇-Text

92 阅读1分钟

Text

字体 .font

字体颜色 .foregroundcolor

文本切换动画

contentTransition .contentTransition(.numericText())

截断 FormatDisplay

Text("Hamlet") .font(.largeTitle) .strikethrough(true,color:.red)

image.png

Text("Hamlet") .font(.largeTitle) .underline(true.color:.green)

image.png

Text("ABCDEF") .kerning(-3) Text("ABCDEF") Text("ABCDEF") .kerning(3)

image.png

Text("ABCDEF") tracking(-3) Text("ABCDEF") Text("ABCDEF") tracking(3)

image.png

Text("Hello") baseline0ffset(-10) .border(Color.red) Text("Hello") .border(Color.green) Text("Hello") .baselineOffset(10) .border(Color.blue) .background(Color(white:0.9))

image.png

Text("Hamlet") .textCase(.uppercase)

image.png

Text("Thisis is a string in a TextField with 10 point spacing applied between the bottom ofonelineandthetopofthenext.") .frame(width:200,height:200,alignment:.leading) .lineSpacing(10) .background(Color.red)

image.png

Text("Thisis is a block of text that will show up in a ttext element as multiple lines.("\n") Here we have chosen to center this ttext." frame(width:200,height:200,alignment:.leadinng) .multilineTextAlignment(.center)

image.png

Text("helloworld") .flipsForRightToLeftLayoutDirection(true) environment(.layoutDirection,.rightToLeft)

image.png