IOS TOPICS

IOS Introduction
Swift UI Label
Swift UI Button
Swift UI Text Field
Swift UI Slider
Swift UI Switch
Swift UI Stepper
Swift UI Date Picker
Swift UI Segmented Control
Views
Table View
Collection Views
SCROLL VIEW
iOS Content View
iOS View Controllers
iOS Bar interface
iOS Navigation interface
iOS Architect Pattern
iOS Libraries
iOS Web request and parsing
iOS user defaults
iOS Coredata and database

Specifying increment Value


Specifying increment Value:

Using “step” define how to update the value stored in the binding value and display it

Code:

struct ContentView: View { @State var Value: Double = 0 var body: some View { VStack { Slider(value: $Value, in: 0...100, step:10) }.padding() Text ("Slider value is \(Int(Value))") } }

Output:

Initial

ios output

On moving the slider

ios output

Making the Slider more Visual:

Add some text using HStacks to show the minimum and maximum values of the slider and display current

Code:

var body: some View { VStack { HStack{ Text("0") Slider(value: $Value, in: 0...100, step:10) Text("100") } }.padding() Text ("Slider value is \(Int(Value))") } }

Output:

ios output

For decimal values upto 2 spaces after the decimal use (and add some font colour) we can change the code as follows :

Code:

var body: some View { VStack { HStack{ Text("0") Slider(value: $Value, in: 0...100, step:10) Text("100") } }.padding() Text("Slider value: \(Value, specifier: "%.2f")") .foregroundColor(.blue) } }

Output:

ios output