To change the accent color of a SwiftUI macOS app, you can do it in any of the following ways:
1. Set Global Accent Color in the .xcassets (I prefer this personally)
- Open
Assets.xcassets - Click
+→ New Color Set - Name it
AccentColor - Set its Appearances to
None(or configure Light/Dark if needed) - Choose a color (e.g., orange)
- Ensure your Info.plist has the key
AccentColorNamepointing toAccentColor(usually done automatically but sometimes you will have to manually add it)
This will apply app-wide unless overridden locally.
2. Set .accentColor in your SwiftUI view
This will apply to the specific view hierarchy:
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.accentColor(.orange) // Change to your desired color
}
}
}
3. Use tint(_:) in SwiftUI 3+ (macOS 12+)
For more recent APIs, Apple recommends using .tint(_:):
ContentView()
.tint(.orange)
Manually modify Info.plist
Ensure your Info.plist has:
<key>NSAccentColorName</key>
<string>AccentColor</string>
Bonus: Dynamically change accent color
If you want to let users choose or switch themes dynamically:
@AppStorage("accentColorName") var accentColorName: String = "blue"
var accentColor: Color {
switch accentColorName {
case "orange": return .orange
case "green": return .green
default: return .blue
}
}
var body: some View {
ContentView()
.tint(accentColor)
}