Binding
https://developer.apple.com/documentation/swiftui/binding
TextField(_ titleKey: LocalizedStringKey, text: Binding<String>, ..)
Picker(_ titleKey: LocalizedStringKey, selection: Binding<SelectionValue>, ..)
Slider(value: Binding<BinaryFloatingPoint>, ..)
..@State var text: String
TextField("Placeholder", text: $text)struct PlayButton: View {
@Binding var isPlaying: Bool
var body: some View {
Button(action: {
self.isPlaying.toggle()
}) {
Image(systemName: isPlaying ? "pause.circle" : "play.circle")
}
}
}
struct PlayerView: View {
var episode: Episode
@State private var isPlaying: Bool = false
var body: some View {
VStack {
Text(episode.title)
Text(episode.showTitle)
PlayButton(isPlaying: $isPlaying)
}
}
}
Last updated