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

时间:2021-03-22 17:06:12

标签: swiftui swiftui-list swiftui-scrollview

我想为水平视图中的社交媒体图标制作一个滚动视图,以便缩放和调整大小,使其看起来像 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")
        
        }
    }
}

0 个答案:

没有答案