SwiftUI - Slider Example.

This tutorial is how to change value using Slider in SwiftUI. As you know in Swift we are using UISlider to change value. Now here in SwiftUI we have a class name Slider to do some thing. first you create SwiftUI Project.




Full Code Slider SwiftUI:
//  Created by Kirit Modi on 17/09/19.
//  Copyright © 2019 iOSDevCenters. All rights reserved.

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()
    }
}
Output:
Thanks.

Checkout the Jooble if your are looking for a job as an iOS developer. 

SwiftUI - Slider Example. SwiftUI - Slider Example. Reviewed by KIRIT MODI on 20:06:00 Rating: 5

No comments:

Powered by Blogger.