<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/swiftui-buttonstyle-hack-that-fixes-dark-mode-fast-klvgcfus2" -->

---
title: SwiftUI ButtonStyle Hack That Fixes Dark Mode Fast
description: Create a custom SwiftUI ButtonStyle that automatically adapts to dark mode by using the @Environment(\.colorScheme) property wrapper. The solution involves...
canonical: https://daily.dev/posts/swiftui-buttonstyle-hack-that-fixes-dark-mode-fast-klvgcfus2
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: SwiftUI ButtonStyle Hack That Fixes Dark Mode Fast | daily.dev
og:description: Create a custom SwiftUI ButtonStyle that automatically adapts to dark mode by using the @Environment(\.colorScheme) property wrapper. The solution involves...
og:url: https://daily.dev/posts/swiftui-buttonstyle-hack-that-fixes-dark-mode-fast-klvgcfus2
og:image: https://api.daily.dev/og/posts/kLVGCfuS2.png
og:image:alt: SwiftUI ButtonStyle Hack That Fixes Dark Mode Fast
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SwiftUI ButtonStyle Hack That Fixes Dark Mode Fast

**[Rebeloper](https://daily.dev/sources/rebeloper)** · 1 min read · 0 upvotes · 0 comments

## Summary

Create a custom SwiftUI ButtonStyle that automatically adapts to dark mode by using the @Environment(\.colorScheme) property wrapper. The solution involves listening to color scheme changes and conditionally setting background and foreground colors based on whether the scheme is dark or light, making the button appearance switch between white/black and black/white color combinations.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=PBYXf4kMi-E>

---

Tags: [#ios](https://daily.dev/tags/ios), [#swift](https://daily.dev/tags/swift), [#swiftui](https://daily.dev/tags/swiftui)

[View this post on daily.dev](https://daily.dev/posts/swiftui-buttonstyle-hack-that-fixes-dark-mode-fast-klvgcfus2)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"SwiftUI ButtonStyle Hack That Fixes Dark Mode Fast","url":"https://daily.dev/posts/swiftui-buttonstyle-hack-that-fixes-dark-mode-fast-klvgcfus2","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/swiftui-buttonstyle-hack-that-fixes-dark-mode-fast-klvgcfus2"},"datePublished":"2026-02-16T11:57:38.936Z","dateModified":"2026-02-16T11:57:53.541Z","description":"Create a custom SwiftUI ButtonStyle that automatically adapts to dark mode by using the @Environment(\\.colorScheme) property wrapper. The solution involves...","image":"https://i.ytimg.com/vi/PBYXf4kMi-E/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/PBYXf4kMi-E/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Rebeloper","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Rebeloper","logo":"https://media.daily.dev/image/upload/s--W0sZL8K4--/f_auto/v1726990075/logos/rebeloper","url":"https://daily.dev/sources/rebeloper"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/swiftui-buttonstyle-hack-that-fixes-dark-mode-fast-klvgcfus2","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ios,swift,swiftui","timeRequired":"PT1M","video":{"@type":"VideoObject","name":"SwiftUI ButtonStyle Hack That Fixes Dark Mode Fast","description":"Create a custom SwiftUI ButtonStyle that automatically adapts to dark mode by using the @Environment(\\.colorScheme) property wrapper. The solution involves...","thumbnailUrl":"https://i.ytimg.com/vi/PBYXf4kMi-E/sddefault.jpg","uploadDate":"2026-02-16T11:57:38.936Z","duration":"PT1M","url":"https://api.daily.dev/r/kLVGCfuS2","embedUrl":"https://www.youtube.com/embed/PBYXf4kMi-E"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Rebeloper","item":"https://daily.dev/sources/rebeloper"},{"@type":"ListItem","position":3,"name":"SwiftUI ButtonStyle Hack That Fixes Dark Mode Fast"}]}
```

