Post

Replies

Boosts

Views

Activity

How do I fix a view size when content will vary?
Three SwiftUI views walk into a bar... well, into an HStack. I have a requirement for this arrangement of controls: [Symbol] [--------Slider--------][Text] [Symbol] [--------Slider--------][Text] The Text views display derived values set by the slider they are next to. At this stage I have put HStacks inside List elements and specified a centre alignment on the stack, which makes everything look nice in the vertical axis. However in the horizontal axis I have two related problems. First, the two sliders are different lengths and not aligned vertically. This is because both the Symbol (Image) and Text views will vary in width between the two List rows. Second, when the sliders are moved, the Text views change size as the content changes, making the sliders also change size. At the same time, I want to allow for Dynamic Type, so using fixed sizes is out of the question. I have toyed with alignment guides and had some success (in other variations of this layout using VStacks and HStacks) and I reckon I could at least get the sliders to start in the same place, but I could not manage to get a second guide working in the same stack, and even if I could, the changing size of the Text views would push this around. I need a way of "reserving" the maximum size for the Text views (I can easily provide the widest string value) from the outset, allowing for Dynamic Type, and also doing the same for the Symbol views. Most of the examples I've seen on this sort of thing use a single alignment guide or rely on leading and trailing alignment, which does not work for more than two elements. This seemed like such a simple example for my first SwiftUI exercise. Any ideas welcome.
2
0
864
Aug ’20
How should I access @AppStorage and @SceneStorage values outside of views?
The two property wrappers @AppStorage and @SceneStorage are great because you can simply redeclare a property in multiple views to share the value and automatically update other views. But how should I access those same values outside of views? I have helper functions which are used in multiple views and which change behaviour based on those stored properties. I believe I could use the old NSUserDefaults.standard to reference the @AppStorage values, but is that the "right" way to do it, and how do I access @SceneStorage values?
8
2
9.6k
Aug ’20
MapKit JS label size on iPhone unreasonably small
I've been working on a MapKit JS map on my Mac for a while with no problems but just tried viewing it on my phone and it is unusable because the label sizes are way too small. Scaling in general is a problem because at this scale my annotations do not even show in portrait mode on my iPhone 11 Pro. My brother's iPhone 12 Pro has a very slightly larger screen (96 pixels taller and 45 pixels wider) and he does see them. On my 11 Pro I have to rotate to landscape before they appear. I cannot find a way to influence the label (or annotation) sizes which implies MapKit JS will "take care of it" for me, but it's doing a terrible job in this case. Am I missing anything?
0
0
691
Jun ’23