微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。