关于Text的段落属性,通过段落属性可以调整文字的字距、行距、偏移值、框架和对齐方式等视觉样式。
示例代码:
VStack{ Text("www.hdjc8.com") Text("www.hdjc8.com") .tracking(10) //字距为10,字距属性表示一组文字的平均字距 Text("www.hdjc8.com") .kerning(10) //字偶间距为10,字偶间距(字距调整)属性表示一对特定字符之间的间距 Text("www.hdjc8.com") .blur(radius: 1) //模糊效果,模糊的半径为1 Text("SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift.") .lineSpacing(20) //行间距 .lineLimit(nil) //不限制文字的行数 Text("www.hdjc8.com") .offset(x: 40, y: 0) //水平方向向右偏移40点的距离 Text("www.hdjc8.com") .frame(width: 200, height: 80, alignment: .bottomTrailing) .background(Color.orange) //文本视图宽高,文字内容位于文本视图的右下角 VStack{ Text("www.hdjc8.com2") .position(x: 50, y: 50) //视图位置,该方法会使对齐属性失效,从视图的左上角向右和向下各便宜50 .frame(width: 300, height: 100, alignment: .bottomTrailing) .background(Color.orange) Text("Interactive\ntutorials\nfor\nXcode!") .multilineTextAlignment(.center) //默认左对齐 .lineLimit(4) //4行显示 Text("Hello\nInteractive Tutorials!").multilineTextAlignment(.leading) //多行文字对齐方式 } }