首页 > 解决方案 > 如何使用 SwiftUI 让我的 UI 很好地适应 iPad 屏幕?

问题描述

struct PasswordGenerator : View {
    var body: some View {
        NavigationView {
            VStack {
                Spacer()
                Text("Upon clicking the button the password\nwill also be copied so you\ncan simply paste")
                    .lineLimit(nil)
                Spacer()
                Button(action: generatePassword) {
                    HStack {
                        Image("GeneratorGlyph")
                        Text("Generate!").font(.title)
                        }
                        .accentColor(.white)
                        .frame(minHeight: 56, maxHeight: 112)
                    .padding(.horizontal, 80)
                    }
                    .background(LinearGradient(gradient: Gradient(colors: [Color.init(red: 48/255, green: 153/255, blue: 216/255), Color.init(red: 65/255, green: 165/255, blue: 237/255)]), startPoint: .topLeading, endPoint: .bottomTrailing), cornerRadius: 9)

                Spacer()
                }
                .navigationBarTitle(Text("Generator"), displayMode: .inline)
        }
    }
}

在此处输入图像描述

这就是代码在 iPad Pro 屏幕上的样子,我不知道如何让它正确扩展。有人知道我该怎么做吗?

标签: iosswiftswiftui

解决方案


推荐阅读