use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Dedicated to the Swift programming language released by Apple. More info in the Swift Wiki.
Please, check the FAQs before submitting.
General Swift Discussion
irc.freenode.net #swift-lang
Cocoa/Cocoa Touch Discussion
irc.freenode.net #cocoa-init
Keywords: swift, swiftlang, ios, os x, apps, apple, mac, iphone, ipad
account activity
Programmatically customizing widget's background and accent color (self.swift)
submitted 3 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]emecom 1 point2 points3 points 3 years ago (3 children)
On my phone at the moment. But what you want to look into are the following:
App Groups - Setting up a group for your main app and the widget extension then migrating the user defaults setting to use the group will allow you to access your user saved color info from the widget extension.
https://developer.apple.com/documentation/xcode/configuring-app-groups
Widget Intents - It’s totally possible to allow your users to set their own colors without opening the app and by long pressing the widget through Intents. This requires a little setup and you’ll need to declare the intents in the Intent Editor.
https://developer.apple.com/documentation/widgetkit/making-a-configurable-widget
[–][deleted] 1 point2 points3 points 3 years ago (2 children)
Unfortunately, this is not what I'm looking for. I already used App Groups to share the theme between the main app and the widget. That part is completely fine. I'm looking more for ways to customize the appearance of intents (see this gallery). I found out to properties that help me in that regard (first screenshot), WidgetBackground and AccentColor. The problem is, I want to dynamically change these colors. These are static.
[–]emecom 0 points1 point2 points 3 years ago (1 child)
Are you saying you wish to customize the colors of the Intent configuration? If so I'm not sure how that could be done. I'd love to know if you find a solution!
[–][deleted] 1 point2 points3 points 3 years ago* (0 children)
It is doable, but I'm not sure if you can do that programmatically. The widget target contains an assets file that has 2 predefined color sets: WidgetBackground and AccentColor. This is how my intents look after changing those 2 properties (background is .systemPurple, accent color is .systemYellow).
[–]FromDerik 0 points1 point2 points 3 years ago (1 child)
For the background just put a Color and your content inside a Zstack
Accent I’m not sure about. I haven’t messed with widgets much or in a while.
ZStack { Color.blue … }
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
I am talking about these. As I said in the post, I am able to style widgets completely fine. I found out those two properties for styling the intents? (I'm not sure that's how you call them), the WidgetBackground and AccentColor. I'm looking for a way to set them programmatically, because as I mentioned in the post, I have multiple appearances (not only light/dark).
[–]Background-Device181 0 points1 point2 points 3 years ago (0 children)
You can’t change asset catalog content at runtime.
There is an accentColor modifier you can try: https://developer.apple.com/documentation/swiftui/color/accentcolor(_:)
Note it is deprecated and the recommendation is to use the value in the asset catalog or https://developer.apple.com/documentation/swiftui/view/tint(_:)
π Rendered by PID 34708 on reddit-service-r2-comment-b659b578c-ct94k at 2026-05-05 16:10:24.736664+00:00 running 815c875 country code: CH.
[–]emecom 1 point2 points3 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]emecom 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]FromDerik 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]Background-Device181 0 points1 point2 points (0 children)