SwiftUI

SwiftUI-Slider

2019-11-19  本文已影响0人  白色天空729

原文链接:https://iosdevcenters.blogspot.com/2019/09/swiftui-slider-example.html

import SwiftUI

struct ContentView: View {

@State var scale: CGFloat = 1.0
    var body: some View {
        VStack {
            Slider(value: $scale, in: 1.0...10.0, step: 0.1)
                .padding(.bottom, 100)
                .frame(width: 200, height: 10, alignment: Alignment.center)

            Text("Slider Value: \(scale)")
                .font(.headline)
                .foregroundColor(Color.red)
                .multilineTextAlignment(TextAlignment.center)
                .background(Color.yellow)
        }
      }
    }

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

输出如图:


Screenshot 2019-09-19 at 9.51.55 AM.png
上一篇下一篇

猜你喜欢

热点阅读