ios - 在 SwiftUI VStack 中,我如何制作多个文本视图,每个视图都有多行文本,宽度相同
问题描述
我正在尝试使 VStack 中的文本具有相同的宽度,但不知道如何。我在其他地方看到它建议为每个文本视图设置一个帧 maxWidth 为 .infinity 但是当我在我的代码中尝试它时它没有任何效果。
这是我的代码:
struct ContentView: View {
var body: some View {
VStack(alignment: .center, spacing: 8.0) {
Spacer()
Text("Youngsters can play in Kids mode. If you're feeling very adventurous you can play in BigKids mode.")
.padding(.horizontal)
Text("Kids mode uses large images and big differences between the number of images shown.")
.padding(.horizontal)
Text("BigKids mode, on the other hand, uses small images and small differences between the number of images shown. Go for it!")
.padding(.horizontal)
Spacer()
}
.frame(maxWidth: 600.0)
}
}
我为 VStack 使用了 600 的帧 maxWidth,因为我不希望它比使用 iPad 时更宽。
这是代码的结果。请注意,每个文本视图的宽度都不同。
解决方案
推荐阅读
- css - 动画只影响 css-doodle 的第一个元素
- react-native - 反应本机多选
- graph - 在neo4j中获取节点的直接子节点
- angular - Angular:如何切换存储库以从公司内部源下载 node_modules 依赖项
- elasticsearch - 用于脚本标签的 Elasticsearch JAVA API
- charts - 如何根据表格中的聚合日期值在 Google Data Studio 中创建饼图?
- c++ - 显式专业化必须在其首次使用之前
- sql - Postgresql > 交叉表查询 > 需要输入
- android - Kotlin - 使用自定义 URL 方案验证 URL
- php - 数据插入失败,但更新工作在 mysql - php 使用 $stmt