SwiftUI Widget DateStyle Custom Format

2.2k views Asked by At

Just wondering if there is a way to apply a custom format for the DateStyle comp within SwiftUI's Text UI. For Example just the minutes or seconds like you would when using a DateFormatter. I want to display the dynamic dates for a Widget but it only offers a limited number of options. Why is this and has anyone found a way around this?

Apple talk more about Displaying Dynamic Dates here: https://developer.apple.com/documentation/widgetkit/keeping-a-widget-up-to-date

1

There are 1 answers

4
samwize On

You won't like this answer, but as of iOS 14, the answer is there's no way to customize the relative style for Text. The relative style is new in iOS 14, and as always, Apple provide the bare minimum feature.

For now, you have only these choices:

  1. Use other Text.DateStyle, if they work for you
  2. Fallback to DateFormatter (and other formatters) with the tradeoff that widget can only refresh couple of times in a day

Hopefully this won't be the answer with iOS 15 or later.