ScrollView内容未填充SwiftUI [英] ScrollView content not filling in SwiftUI

查看:114
本文介绍了ScrollView内容未填充SwiftUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个scrollview,其内容为VStack,其中包含一个ForEach循环,用于创建一些行而不是一个列表.列表有一些缺点,例如分隔线.

I have a scrollview which content is a VStack containing a ForEach loop to create some Rows instead of a list. A List has some downsides like the dividers.

我的问题是该行没有填充滚动视图.我认为scrollview宽度不能填满屏幕.

My Issue is that the Row is not filling the scrollview. I think the scrollview width is not filling the screen.

NavigationView {
        Toggle(isOn: $onlineStatus) {
            Text("Online Only")
        }.padding([.leading, .trailing], 15)

        ScrollView {
            VStack(alignment: .trailing) {
                ForEach(onlineStatus ? self.notes.filter { $0.dot == .green } : self.notes) { note in
                    NavigationButton(destination: Text("LOL")) {
                        CardRow(note: note)
                            .foregroundColor(.primary)
                            .cornerRadius(8)
                            .shadow(color: .gray, radius: 3, x: 0, y: -0.01)
                    }.padding([.leading, .trailing, .top], 5)
                }.animation(self.onlineStatus ? .fluidSpring() : nil)
            }
        }.padding([.leading, .trailing])

        .navigationBarTitle(Text("Your documents"))
    }

这给了我这个结果:

那是我的CardRow:

That's my CardRow:

struct CardRow: View {
var note: Note

var body: some View {
    HStack {
        Image(uiImage: UIImage(named: "writing.png")!)
            .padding(.leading, 10)

        VStack(alignment: .leading) {
            Group {
                Text(note.message)
                    .font(.headline)
                Text(note.date)
                    .font(.subheadline)
            }
            .foregroundColor(.black)
        }

        Spacer()
        VStack(alignment: .trailing) {
            Circle().foregroundColor(note.dot)
                .frame(width: 7, height: 7)
                .shadow(radius: 1)
                .padding(.trailing, 5)
            Spacer()
        }.padding(.top, 5)
    }
    .frame(height: 60)
    .background(Color(red: 237/255, green: 239/255, blue: 241/255))
}

}

推荐答案

尝试将RowView的帧宽度设置为UIScreen.main.bounds.width: .frame(width: UIScreen.main.bounds.width)

Try setting the frame width of the RowView to UIScreen.main.bounds.width: .frame(width: UIScreen.main.bounds.width)

这篇关于ScrollView内容未填充SwiftUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆