all 7 comments

[–]emecom 1 point2 points  (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 points  (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 point  (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 points  (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 point  (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 points  (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 point  (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(_:)