首页 > 解决方案 > 在 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 时更宽。

这是代码的结果。请注意,每个文本视图的宽度都不同。

代码结果

标签: iosswiftuivstack

解决方案


推荐阅读