How to make stepper with plus and minus buttons in SwiftUI for macOS

Issue #717

Try to use predefined system colors in Human Interface Guidelines for macOS

Here we use this color unemphasizedSelectedTextBackgroundColor for button background

Screenshot 2020-12-21 at 06 24 16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
HStack(spacing: 1) {
makeUnderListButton(action: {}, icon: .plus)
makeUnderListButton(action: {}, icon: .minus)
}
.background(Color(NSColor.unemphasizedSelectedTextBackgroundColor))
.cornerRadius(4)

func makeUnderListButton(action: @escaping () -> Void, icon: AwesomeIcon) -> some View {
Button(action: action) {
Text(icon.rawValue)
.font(.awesome(style: .solid, size: 14))
}
.buttonStyle(HighlightButtonStyle(h: 8, v: 6, cornerRadius: 4))
}

Another thing is List, where we have selected and alternative background colors. We should also use dynamic system colors selectedContentBackgroundColor and alternatingContentBackgroundColors

1
2
3
4
5
6
7
8
9
10
11
12
13
VStack {
ForEach(apps.enumerated().map({ $0 }), id: \.element) { index, app in
makeRow(app: app)
.onTapGesture {
self.selected = app
}
.background(
self.selected == app
? Color(NSColor.selectedContentBackgroundColor)
: Color(NSColor.alternatingContentBackgroundColors[index % 2])
)
}
}

Read more


Updated at 2020-12-21 05:56:28

Comments