Declaration
compose().paletteSelectionEffect(
effect: SwiftUI.PaletteSelectionEffect
)nonisolated func paletteSelectionEffect(
_ effect: PaletteSelectionEffect
) -> some ViewParameters
The type of effect to apply when a palette item is selected.
Discussion
PaletteSelectionEffect.automatic applies the system's default
appearance when selected. When using un-tinted SF Symbols or template
images, the current tint color is applied to the selected items' image.
If the provided SF Symbols have custom tints, a stroke is drawn around selected items.
If you wish to provide a specific image (or SF Symbol) to indicate
selection, use PaletteSelectionEffect.custom to forgo the system's
default selection appearance allowing the provided image to solely
indicate selection instead.
The following example creates a palette picker that disables the system selection behavior:
Menu {
Picker("Palettes", selection: $selection) {
ForEach(palettes) { palette in
Label(palette.title, image: selection == palette ?
"selected-palette" : "palette")
.tint(palette.tint)
.tag(palette)
}
}
.pickerStyle(.palette)
.paletteSelectionEffect(.custom)
} label: {
...
}If a specific SF Symbol variant is preferable instead, use
PaletteSelectionEffect.symbolVariant(_:).
Menu {
ControlGroup {
ForEach(ColorTags.allCases) { colorTag in
Toggle(isOn: $selectedColorTags[colorTag]) {
Label(colorTag.name, systemImage: "circle")
}
.tint(colorTag.color)
}
}
.controlGroupStyle(.palette)
.paletteSelectionEffect(.symbolVariant(.fill))
}See also
More in Lists and tables.
- deleteDisabledAdds a condition for whether the view's view hierarchy is deletable.
- listItemTintSets the tint effect for content in a list.
- listRowBackgroundPlaces a custom background view behind a list row item.
- listRowInsetsSets the insets of rows in a list on the specified edges.
- listRowSeparatorSets the display mode for the separator associated with this specific row.
- listRowSeparatorTintSets the tint color associated with a row.
- listRowSpacingSets the vertical spacing between two adjacent rows in a List.
- listSectionIndexVisibilityChanges the visibility of the list section index.
- listSectionMarginsSet the section margins for the specific edges.
- listSectionSeparatorSets whether to hide the separator associated with a list section.
- listSectionSeparatorTintSets the tint color associated with a section.
- listSectionSpacingSets the spacing between adjacent sections in a List to a custom value.