Skip to content

Instantly share code, notes, and snippets.

@imthath-m
Last active January 21, 2023 14:04
Show Gist options
  • Save imthath-m/c676f64070d4ef970e8218c439c99de7 to your computer and use it in GitHub Desktop.
Save imthath-m/c676f64070d4ef970e8218c439c99de7 to your computer and use it in GitHub Desktop.
Sample View to demonstrate how often SwiftUI redraws its views.
import SwiftUI
struct SampleView: View {
var texts = ["SwiftUI", "A new declarative UI framework", "Let us try to understand how SwiftUI renders its views"]
@State var selected = 0
@State var textFieldValue = ""
@State var isSwitchOn = false
var body: some View {
VStack(spacing: 16) {
TextField("Enter your name", text: $textFieldValue)
.padding(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
.background(Color(UIColor.secondarySystemFill))
.cornerRadius(4)
Toggle(isOn: $isSwitchOn, label: {
Text("A simple Switch")
})
Picker(selection: $selected, label: Text(""), content: {
Text("Word").tag(0)
Text("Phrase").tag(1)
Text("Sentence").tag(2)
}).pickerStyle(SegmentedPickerStyle())
HStack {
Text(texts[selected])
Spacer()
Button(action: {
print("just checking")
}, label: {
Image(systemName: "plus.circle.fill")
.foregroundColor(.blue)
})
}
}.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment