I think I have a way to address this.
I changed the accessibilityLabel to be "Favorite Button" and added accessibilityValue with the current value.
After that VoiceOver is no longer always saying the toggle is off.
Button {
showFavActions()
} label: {
Image(systemName: SFSymbolShortcut.star.rawValue)
.symbolVariant(weatherData.currentlyFavIndex == nil ?
.none : .fill)
}
.buttonStyle(.plain)
.accessibilityLabel(Text("Favorite Button"))
.accessibilityHint(Text(weatherData.currentlyFavIndex == nil ?
"Add to favorites." :
"Remove from favorites."))
.accessibilityInputLabels(["Favorite"])
.accessibilityAddTraits(.isToggle) // iOS 17
.accessibilityValue(weatherData.currentlyFavIndex == nil ?
"Not a favorite location." :
"Favorite location.")
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: