首页 > 解决方案 > 如何在 SwiftUI 中使列表更宽?

问题描述

我现在正在学习 SwiftUI,并且正在编写教程。

但是在 SwiftUI List 中,name 的部分被剪掉了。你有修饰符吗?

struct ContentView: View {
    var body: some View {
        List(modelData) {
            Device in HStack {
                Image(systemName: Device.image)
                    .frame(width: 50, height: 10, alignment: .leading)
                    Text("\(Device.name)")
                    .frame(width: 50, height: 10, alignment: .leading)
                    .scaledToFit()
                    VStack {
                    Text("\(Device.price)")
                }
            }
            .font(.title)
        }
    }

}

在此处输入图像描述

标签: swiftxcodeswiftui

解决方案


而不是像你一样限制

    Text("\(Device.name)")
    .frame(width: 50, height: 10, alignment: .leading)
    .scaledToFit()

只用

    Text("\(Device.name)")

它将自动调整大小以适合


推荐阅读