Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI Widget DateStyle Custom Format

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

like image 989
Russ Avatar asked Mar 31 '26 19:03

Russ


1 Answers

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.

like image 80
samwize Avatar answered Apr 03 '26 10:04

samwize