首页 > 解决方案 > 滚动视图填充而不减少可滚动区域?

问题描述

我怎样才能使 Text 在滚动视图周围获得一个框架,以便可滚动区域不会减少。如果我要在 ScrollView 周围添加填充,那么小框架将不会接收到滚动视图的拖动。

我有这个布局:

struct ContentView: View{
    let width: CGFloat = UIScreen.main.bounds.width
    let height: CGFloat = 100
    var body: some View{
        HStack{
            ScrollView(){
                Text("""
                    test test test test
                    test test test test
                    test test test test
                    test test test test
                    test test test test
                    test test test test
                    test test test test
                    test test
                """)
                    .padding(.vertical)
            }
            .frame(width: width * 0.5)
        }
        .frame(width: width * 0.9,height: height)
        .background(RoundedRectangle(cornerRadius: 10).foregroundColor(Color.red))
    }
}

标签: swiftswiftui

解决方案


推荐阅读