Skip to main content

swiftui-button-role-2 | ios-app-dev-memo

SwiftUI Button

Role を指定

swift
Button("Cancel", role: .cancel) {
}

ボタンの色を青でなくしたいが、ダークモードのために black などは指定したくない。 -> tint を指定すれば良い

swift
Button {
...
} label: {
HStack {
Text("タイトル")
.foregroundStyle(.primary) // 黒
Spacer()
Group {
Text("値")
Image(systemName: "chevron.up.chevron.down")
.font(.footnote)
}
.foregroundStyle(.secondary) // グレー
}
}
.tint(.primary) // これが通常だと .accentColor なのだろう