当前位置:   article > 正文

SwiftUI - ScrollView_swiftui scrollview

swiftui scrollview


https://developer.apple.com/documentation/swiftui/scrollview


Vertical

在这里插入图片描述


struct ContentView : View
{
    var body: some View
    {
        ScrollView(.vertical, showsIndicators: false)
        {
            VStack(alignment: HorizontalAlignment.leading, spacing: 20)
            {
                Text("Overview")
                    .font(.system(size: 48))
                    .padding(10)
                
                Text("With the power of Xcode, the ease of Swift, and the revolutionary features of cutting-edge Apple technologies, you have the freedom to create your most innovative apps ever.\nSwiftUI provides views, controls, and layout structures for declaring your app's user interface.  ")
                    .lineLimit(nil)
                    .frame(width: 300, height: 160, alignment: .topLeading)
                    .padding(10)
                
                Image("iPhone")
                    .resizable()
                    .frame(width: 300, height: 556, alignment: .center)
            }
        }
        .background(Color.yellow)
        .padding(10)
        .navigationBarTitle(Text("ScrollView"))
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

Horizontal

在这里插入图片描述


struct ContentView : View
{
    var body: some View
    {
        ScrollView(.horizontal, showsIndicators: true)
        {
            HStack(alignment:.center, spacing: 20)
            {
                ForEach( 1 ..< 8)
                {i in
                    Image("0\(i)")
                        .resizable()
                        .scaledToFill()
                        .frame(height: 160)
                }
            }
        }
        .padding(20)
        .background(Color.black.opacity(0.1))
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

VerticalAndHorizontal

struct ContentView : View
{
    var body: some View
    {
        ScrollView(.vertical, showsIndicators: false)
        {
            VStack(alignment: HorizontalAlignment.leading, spacing: 10)
            {
                Text("Overview")
                    .font(.system(size: 48))
                    .padding(20)
                
                Text("SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift. Build user interfaces for any Apple device using just one set of tools and APIs.")
                    .lineLimit(nil)
                    .frame(width: 300, height: 120, alignment: .topLeading)
                    .padding(20)
                
                ScrollView(.horizontal, showsIndicators: true)
                {
                    HStack(alignment:.center, spacing: 20)
                    {
                        Image("iPhone")
                            .resizable()
                            .frame(width: 189, height: 350, alignment: .center)
                        
                        Image("iPhoneSerial")
                            .resizable()
                            .frame(width: 518, height: 350, alignment: .center)
                        
                        Image("iPhone")
                            .resizable()
                            .frame(width: 189, height: 350, alignment: .center)
                    }
                }
                .padding(10)
                .background(Color.black)
            }
        }
        .background(Color.orange)
        .padding(10)
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号