SwiftUI:如何为图标水平创建滚动视图

问题描述

我想为水平视图中的社交媒体图标制作一个滚动视图,以便缩放和调整大小,使其看起来像 this image

-我应该使用滚动视图还是列表视图?也可以横向

我已经尝试过此代码,但它不起作用,您是否有任何我可能遗漏的解决方案?

struct ContentView: View {
    var body: some View {
        NavigationView {
            vstack(alignment: .leading,spacing: 20){
            Text("Total number of posts we've analyzed so for : 35.513.682")
                .frame(width: 300,height: 50,alignment: .topLeading)
                .padding()
                .background(Color(#colorLiteral(red: 0.2549019754,green: 0.2745098174,blue: 0.3019607961,alpha: 1)))
                .cornerRadius(15)
                .multilineTextAlignment(.leading)
                Spacer()
                    .frame(height: 5)
                
                Text("Which social media do you generate hashtags for?")
                    .multilineTextAlignment(.leading)
                    
                            
               Spacer()
                
                //Scroll view
                ScrollView(.horizontal,showsIndicators: false){
                    HStack(spacing: 20){
                        ForEach(0..<10){ index in
                            Image( "facebook")
                            Image( "instagram")
                            Image( "flickr ")
                            Image( "google-plus")
                            Image( "linkedin")
                            Image( "pinterest")
                            Image( "tik-tok")
                            Image( "tumblr")

                        }
                        
                        .frame(width: 100,height: 100,alignment: .center)
                        .padding()
                    }//hs
                    
                   

                }
                    
                    
      
            
            
            }//vs
            .navigationTitle(Text("Hashtags"))
        
    }// NV
}
}
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            ContentView()
                .preferredColorScheme(.dark)
                .previewDevice("iPhone 11")
        
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...