I am currently making a widget only application based on SwiftUI that allow users to show some type of informations as time, date etc.. In order to make my application functional I would like to make a preview of the widgets in the app view, also allowing users to set it up.
For now everything is working well, I can select a widget in my application and set it up so the widget updates as well. However, I am facing a problem, after some researches I can’t seem to find a way that allows you to get the widgets sizes according to the device you are using.
I tried to use UIScreen.main.bounds.size
but the aspect ratio between widgets sizes and devices sizes aren’t the same.
What I would like to do is making my widget preview adapt to the widgets sizes that the device is actually using. (in other words retrieve the widgets sizes depending on which device you are on)
Is there any solutions to do it dynamically or do I need to make a view for each devices? Thanks in advance.
You could map UIScreen.main.bounds.size to widget sizes from Apple documentation: https://developer.apple.com/design/human-interface-guidelines/widgets/overview/design/
Example for a Small widget: