Swift 使用 Text 视图创建静态标签的步骤如下:
- 在代码中创建一个 Text 视图。
Text("This is a static label")
- 使用 Text 视图的属性来自定义标签。例如,可以设置字体、字体颜色、对齐方式等。
Text("This is a static label")
.font(.title)
.foregroundColor(.blue)
.multilineTextAlignment(.center)
- 将 Text 视图添加到视图的层次结构中。
struct ContentView: View {
var body: some View {
VStack {
Text("This is a static label")
.font(.title)
.foregroundColor(.blue)
.multilineTextAlignment(.center)
// 其他视图
}
}
}