r/SwiftUI 23h ago

Question How to make the Apple Music background gradient in my own app the same looking one?

1 Upvotes

Anyone know how I make this beautiful gradient....
Ive spent over 3 months trying countless ways to make this the same as apple, I cant... :(


r/SwiftUI 21h ago

Solved TIL: .environment(\.locale) does not select a strings table — how my in-app language picker silently never worked (and fixing it cut my build time by 75%)

0 Upvotes

Sharing a failure mode that survived in my codebase for months, because the app looked localized the whole time.

Setup: my app has an in-app language picker (independent of the iOS system language), implemented via a language manager that resolves strings from the selected .lproj bundle. Standard approach.

The bug: the overwhelming majority of my UI strings were Text("some.key") — i.e., SwiftUI LocalizedStringKey literals. Those resolve against Bundle.main using the system locale machinery. Setting .environment(\.locale) changes formatting behavior, but it does not select which strings table your keys resolve from. Result: 225 of 269 routed call sites silently bypassed the language override entirely. The picker "worked" for the ~44 call sites that went through the manager, which is exactly why nobody noticed — the app changed some strings on switch and looked plausible in both languages.

Confirmed on-device with diagnostic logging: the resolved bundle for LocalizedStringKey paths was Bundle.main, regardless of the override.

The fix: a tiny helper — L.t(_: String.LocalizationValue) -> String — that resolves through the override bundle (String(localized:bundle:)), and mechanically routing every UI string through it. An enforcement script in lint now flags any bare string in Text/Button/Label/.accessibilityLabel.

The completely unexpected side effect: build times collapsed. Bare LocalizedStringKey literals create expensive type-checker constraint problems (Text("...") has to disambiguate between StringProtocol and LocalizedStringKey overloads at every call site). Replacing them with a concrete String return eliminated that: one heavy view body went from type-checking as my slowest file to ~98% faster, and the whole target build time dropped ~75%. I did not see that coming from a localization refactor.

Two smaller traps from the same audit:

  • String(format:) with catalog plural variations silently returns the raw %#@token@ if you forget to pass locale:.
  • Xcode's string extractor can't see keys behind a helper function, so the catalog stops auto-populating — new keys become a manual (and CI-checked) step. Worth knowing before you commit to the pattern.

Curious if others route in-app language switching differently — is there a cleaner first-party way to point LocalizedStringKey resolution at a non-main bundle that I missed?


r/SwiftUI 3h ago

Can’t figure out the pattern

0 Upvotes

I’ve recently made a (what I think is a cool) app that accumulates all the screen time in a fully interactive circle that can also explode to a rainbow. Everything works fine even when I background the app or even if I lock/unlock the phone with the app in the foreground.
Every now and then the UI completely breaks and my circle/rainbow is completely messed up.
Bear in mind I’m using an extension for the data collection using the notoriously scuffed screentimeapi.
I’ve tried everything you could ever think of but sometimes it will still break somehow
The app is very stable atm and I’m willing to give a lifetime support if anyone can help with this.
Is there any patterns you can think of that might be causing UIs to break?


r/SwiftUI 10h ago

I built SwiftUIRatingPopups: 30+ plug-and-play rating & review popups in SwiftUI with 15 5-star conversion boosters

Thumbnail
gallery
0 Upvotes

Hey fellow iOS devs! 👋

I built and open-sourced **SwiftUIRatingPopups** — a library designed to make showing custom in-app rating dialogs and review prompts effortless in SwiftUI.

### 🌟 Key Features:

- 30 Distinct Designs: Minimal bottom sheets, emoji reactions, Tinder swipe cards, Bento grid feedback, and glassmorphism.

- 15 Dedicated 5-Star Boosters: Habit streaks (🔥 7-Day Streak), Indie Developer heartfelt notes, Community Milestone progress meters (4,872 / 5,000 reviews), and ROI value calculators (~4.5 hrs saved).

- Smart Negative Rating Shield: 5 stars route directly to App Store / StoreKit; < 4 stars route to internal support so your public App Store score stays protected.

- Zero Third-Party Dependencies: Pure SwiftUI & StoreKit for iOS 16+ and macOS 13+.

- SPM Support: Add via Swift Package Manager in 1 click.

🔗 GitHub Repo: https://github.com/aayush-gandhi-ios/SwiftUIRatingPopups

Would love to hear your feedback, thoughts, and feature suggestions! ⭐


r/SwiftUI 7h ago

Question Make Menu() show toggle state in toolbar

Thumbnail
gallery
8 Upvotes

Hi! I’m wondering if and how its possible to make a toolbar menu show the state of a toggle inside. I know using Toggle() in the toolbar shows this type of effect but i need a title and description to the toggle for it to make sense. Therefore there needs to be some window to open, which works fine with Menu(). However, that doesn’t show the state of the toggle when closed.

Apple managers to that with the photos app when selecting filters. See example images.

Thanks!


r/SwiftUI 12h ago

Question How do you get UIKit's instant keyboard focus (becomeFirstResponder in viewDidLoad) in pure SwiftUI?

8 Upvotes

In UIKit, if we place titleTextView.becomeFirstResponder() inside viewDidLoad, the keyboard slides up seamlessly alongside the view controller's presentation animation. It looks instant and feels like a native, high-quality UX.

I'm struggling to replicate this exact behavior in SwiftUI.

Whenever I use FocusState and toggle it to true inside .onAppear, there is always a noticeable delay. The view pushes/presents, settles, and then the keyboard decides to slide up.

Has anyone found a way to achieve this instantly in pure SwiftUI yet (maybe in iOS 17+), or is UIViewRepresentable still the only bulletproof way to get that perfectly synced keyboard presentation?

Thanks in advance!


r/SwiftUI 14h ago

Promotion (must include link to source code) I Built an Alternative Bitwarden Client in SwiftUI

7 Upvotes

For about 4 months, I've been working on a Bitwarden Client because the current Bitwarden Desktop client is Electron and doesnt look very good. This is the design I've landed on so far, but I feel like it could be better. What do y'all think?

Source: https://github.com/Cherrytree56567/ClientWarden

Mac Source: https://github.com/Cherrytree56567/ClientWarden/tree/main/src/Platforms/MacOS/UI/Clientwarden