SwiftUI列表NavigationLink框架的问题(高度:CGFloat)

时间:2019-07-08 00:49:57

标签: ios swift swiftui ios13

我正在尝试为我的列表行显示一个自定义视图,它是一个带有图像,标题文本和另一个包含简短段落的文本的HStack。我对NavigationLink项目的高度有疑问。我尝试将框架设置为特定的高度,但是在不同的设备上无法最佳显示(iPhone XR和iPhone XS之间的微小分辨率差异足以让我不得不手动调整高度)。

是否可以自动设置边框高度?我已经尝试了很多方法,例如在PlanetRow View上设置框架高度,添加填充,将lineLimit设置为:0、3、5……无论我做什么,如果我没有为NavigationLink View设置高度, PlanetRow延伸经过NavigationLink视图(在列表分隔符之外可见)。

这是我的观点的代码:

struct PlanetRow : View {
    var planet: Planet

    var body: some View {
        HStack {
            Image("Mars")
                .resizable()
                .frame(width: 50, height: 50)
            VStack(alignment: .leading) {
                Text(planet.name)
                    .font(.largeTitle)
                Text(planet.overview)
                    .font(.caption)
            }
            .lineLimit(nil)
        }
    }
}

struct PlanetList : View {
    var body: some View {
        NavigationView {
            List(planetData.identified(by: \.id)) { planet in
                NavigationLink(destination: PlanetDetail(planet: planet)) {
                    PlanetRow(planet: planet)
                }
                .frame(height: 150)
            }
            .navigationBarTitle(Text("Planets"))
        }
    }
}

NavigationLink with Frame Height NavigationLink without Frame Height

0 个答案:

没有答案