Discussion 議論
For example: 例えば:
ForEach(items) {
ItemView(value: item, isSelected: item.id == selectedID)
}
struct ItemView {
var value: item
var isSelected: Bool
var body: some View {
// construct the actual cell content
.background(selectionBackground)
}
private var selectionBackground: some View {
if isSelected {
RoundedRectangle(cornerRadius: 8)
.fill(.selection)
}
}
}
On macOS and iPadOS this automatically reflects window key state and focus state, where the emphasized appearance will be used only when the window is key and the nearest focusable element is actually focused. On iPhone, this will always fill with the environment’s accent color.
For information about how to use shape styles, see Shape
.