Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

SwiftUI Documentation

Posts under SwiftUI subtopic

Post

Replies

Boosts

Views

Activity

how to change the textfield background on click focused
i am using this code but no works @FocusState private var focus: FormFieldFocus? let db = getDatabaseConnection() var body: some View { VStack { Group { Text("Item Num:").padding(1) TextField("Item Num", text: $intemNum) .textFieldStyle(.roundedBorder) .onSubmit {focus = .despTxt} .focused($focus, equals: .itemTxt) .background(focus ? Color.yellow.opacity(0.3) : Color.clear) .cornerRadius(10)
Topic: UI Frameworks SubTopic: SwiftUI
2
0
160
Jul ’25
tabBarMinimizeBehavior not working if subview has TabView with .tabViewStyle(.page)
We are using a TabView as the TabBarController in our app for main navigation. On one of the tabs we have a view that consists of a TabView with .tabViewStyle(.page) in order to scroll horizontally between pages inside of that specific tab. The .tabBarMinimizeBehavior(.onScrollDown) works on all the other TabItem views, but for this one it does not recognise any vertical scrolling in any of the pages, in order to minimize the TabBar. I believe this is a bug? If we don't wrap the views inside the TabView with .page style, we are able to get the expected behaviour using the tabBarMinimizeBehavior. Please let us know if this is going to be fixed in a future iOS 26 beta release.
0
3
119
Jul ’25
glassEffect modifier makes DragGesture no longer work
I have the following SwiftUI code for a draggable UI. private var onTouchDownGesture: some Gesture { DragGesture(minimumDistance: 0) .onChanged { value in isDragging = true updateYTranslation(value.translation.height) } .onEnded { value in isDragging = false updateYTranslation(value.translation.height) } } var body: some View { VStack { Image(systemName: "chevron.up") Spacer() .frame(height: 16) Image(systemName: "chevron.down") } .padding() .gesture(onTouchDownGesture) .glassEffect(.regular.interactive(false)) } } I find that if I use glassEffect modifier, then the drag gesture will not work. However, if i change it glasseffectto other kinds of background like .background(Capsule()), then the drag gesture works as expected. Is this a known issue of glassEffect or am I using it incorrectly?
1
0
184
Jul ’25
Liquid Glass Error
Hello everyone. I'm getting an error in my code and I don't know why. Can someone explain it to me? import SwiftUI struct ContentView: View{ var body: some View{ VStack { Button {} label: { Text("Click Me") } .buttonStyle(.glass) .frame(width: 200, height: 200) } } } The error is as follows: Reference to member 'glass' cannot be resolved without a contextual type Thanks for your help
1
0
196
Jul ’25
How to replicate Mail toolbar
The toolbar in the the Mail app uses seems to force a .soft scrollEdgeEffectStyle, however I can't seem to reproduce this. Even when putting .scrollEdgeEffectStyle(.soft, for: .top) all over my code, a NavigationSplitView seems to force a "classic" toolbar. Example, top is the mail app, bottom is my swiftUI app:
0
0
132
Jul ’25
Shield Configuration For ManagedSettingsUI not applying for Category Selections
So when we select an app that needs to have a shield configured for family controls (managed settings), when selecting an individual application (say like Instagram), it works well but when I select a whole category (say like Social) it doesn't work well. here's the exact code for how I choose which application needs to be shielded: class ShieldConfigurationExtension: ShieldConfigurationDataSource { override func configuration(shielding application: Application) -> ShieldConfiguration { return ShieldConfiguration( backgroundBlurStyle: .systemChromeMaterial, backgroundColor: UIColor(red: 220.0/255, green: 20.0/255, blue: 60.0/255, alpha: 1.00), icon: iconImage, title: ShieldConfiguration.Label(text: "You CAN'T give up now!", color: .white), subtitle: ShieldConfiguration.Label(text: "Just a little bit more you got this", color: .white), primaryButtonLabel: ShieldConfiguration.Label(text: "GRINDSET", color: .white), primaryButtonBackgroundColor: .black, secondaryButtonLabel: ShieldConfiguration.Label(text: "Move Fast", color: .black) ) } Now this works well for application selection alone, but there isn't any for category selection as such. And the same is shown in its execution that a category goes back to default shielding. What API should I use for category shielding?
1
0
177
Jul ’25
Content bleeding through `.fullScreenCover`
When building with the iOS 26 SDK (currently beta 4) and using the .fullScreenCover modifier in conjunction with a TabView, content from the background view bleeds through the .fullScreenCover making the UI fairly illegible. How to reproduce The gifs below show the bleed through in iOS 26 and the previous behavior of the same code in iOS 18. iOS 24 beta 4 iOS 18.5 Code The code below was used to demonstrate the issue seen in the gifs above. import SwiftUI struct FullScreenCoverBleed: View { @State private var isPresentingRegistration = false var body: some View { NavigationStack { TabView { Tab("Home", systemImage: "house") { Button("Create Account") { isPresentingRegistration = true } .buttonStyle(.borderedProminent) .fullScreenCover(isPresented: $isPresentingRegistration) { RegistrationWizard() } List { ForEach(1 ..< 11) { index in Text("Article \(index)") } } .listStyle(.plain) } Tab("Settings", systemImage: "gear") {} } } } } struct RegistrationWizard: View { var body: some View { // A page-style wizard TabView { // Page 1 VStack { Text("Page 1").font(.largeTitle) Text("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") Spacer() } // Page 2 Form { TextField("Username", text: .constant("")) // Fields for password, email, and so on ... } // Page 3 and so on... } .tabViewStyle(.page(indexDisplayMode: .automatic)) } } Where bleed-through occurs Starting View (before .fullScreenCover) Full Screen Cover VStack Full Screen Cover Form .sheet doesn't have this problem Interestingly, if you use a .sheet instead of a .fullScreenCover, everything works as expected. As shown below, there's no bleed-through when using a .sheet: Next steps? Is there a recommended way to prevent this bleed-through? Or is this perhaps a known bug in iOS 26 beta 4?
Topic: UI Frameworks SubTopic: SwiftUI
3
0
137
Jul ’25
Illegible navigation title when presenting Map view
When building with the iOS 26 SDK (currently beta 4), the navigation title is often illegible when rendering a Map view. For example, note how the title "Choose Location" is obscured by the map's text ("South America") in the screenshot below: This screenshot is the result of the following view code: import MapKit import SwiftUI struct Demo: View { var body: some View { NavigationStack { Map() .navigationTitle(Text("Choose Location")) .navigationBarTitleDisplayMode(.inline) } } } I tried using the scrollEdgeEffectStyle(_:for:) modifier to apply a scroll edge effect to the top of the screen, in hopes of making the title legible, but that doesn't seem to have any effect. Specifically, the following code seems to produce the exact same result shown in the screenshot above. import MapKit import SwiftUI struct Demo: View { var body: some View { NavigationStack { Map() .scrollEdgeEffectStyle(.hard, for: .top) // ⬅️ no apparent effect .navigationTitle(Text("Choose Location")) .navigationBarTitleDisplayMode(.inline) } } } Is there a recommended way to resolve this issue so that the navigation title is always readable?
4
3
172
Jul ’25
Swift UI の 日時表示の.timerでのコロン(:)のユニコードについて
I'm currently exploring ways to update a widget's display independently of the timeline mechanism. While researching, I came across this thread and started experimenting with the approach: https://developer.apple.com/forums/thread/720640 As part of the implementation, I'm attempting to render a 00:00-style time string using a single custom font glyph via .timer. However, I noticed that the colon character used in .timer doesn't appear to be the standard Unicode 0x003A (colon). It seems to be a different character entirely. Does anyone happen to know exactly which character this colon is? Any insights would be appreciated.
0
0
35
Jul ’25
iPadOS textFormatting menu does not appeared
I have this in my swift file: CommandGroup(replacing: .textFormatting) { Toggle("Bold Text", systemImage: "bold", isOn: boldBinding) .keyboardShortcut("B") Button("Align Left", systemImage: "text.alignleft") { alignmentBinding.wrappedValue = 1 } .keyboardShortcut("[") Button("Align Center", systemImage: "text.aligncenter") { alignmentBinding.wrappedValue = 0 } .keyboardShortcut("\\") Button("Align Right", systemImage: "text.alignright") { alignmentBinding.wrappedValue = 2 } .keyboardShortcut("]") } Nothing appeared in iPadOS menu (but does appeared on Mac). Change textFormatting to textEditing does work, but appeared in a very long menu
Topic: UI Frameworks SubTopic: SwiftUI
0
0
68
Jul ’25
iOS 26 Beta breaks scroll/gesture in SwiftUI chat (worked in iOS 18): Simultaneous gestures & ScrollViewReader issues
Hi all, After upgrading to the iOS 26 beta, the scrolling in my SwiftUI chat view is completely broken. The exact same code works perfectly on iOS 18. Context: I have a chat view using ScrollViewReader and a vertically-reversed ScrollView (with .rotationEffect(.degrees(180))). Each message row (MessageBubble) uses multiple simultaneousGesture handlers: Horizontal drag for swipe-to-reply (and other actions: pin, delete) Long press for showing popover/actions Vertical scroll for normal chat scrolling This was working great on iOS 18. In iOS 26 beta, the vertical scroll is either completely disabled, jittery, or hijacked by the message row’s drag gestures, even though .simultaneousGesture is used (see code below). Minimal Repro Sample MessageListView.swift swift Copy Edit ScrollViewReader { proxy in ScrollView(.vertical, showsIndicators: false) { LazyVStack(spacing: 0) { // ... grouped messages ForEach(...) { ... MessageBubble(...) // see below } Color.clear.frame(height: 8).id("BOTTOM_ANCHOR") } .padding(.horizontal, 4) .rotationEffect(.degrees(180)) } .rotationEffect(.degrees(180)) } MessageBubble.swift struct MessageBubble: View { // ... var body: some View { // horizontal swipe-to-reply gesture let dragGesture = DragGesture(minimumDistance: 10) // ... ZStack { // ... HStack { ... } // ... .simultaneousGesture( DragGesture(minimumDistance: 0) // for long press // ... ) .simultaneousGesture(dragGesture) // for horizontal swipe } // ... } }
5
7
222
Jul ’25
watchOS image alignment issue
Hello developers, Now I'm facing a issue with a image alingment on watchOS app. As you see below, I load a UIImage on a view of watchOS app using SwiftUI and would like to fill the watch screen fully with the image. (That's why I added '.ignoreSafeAre()' modifier) As expected, the image fills the screen but the image is aligned to the left only in case of a landscape image (width > height). I tried anything I imagine, but all failed. Can anybody give a hint or advice to solve this issue? Many thanks in advance! ZStack{ Image(uiImage: image) .resizable() .aspectRatio(contentMode: .fill) .ignoresSafeArea() .scaleEffect(zoom) .offset(...) .gesture(... }
0
0
60
Jul ’25
Using ConcentricRectangle as a ButtonBorderShape
With Xcode 26.0 Beta 4 the container concentric API is finally available, which is great! What I was wondering is how to use this API for button shapes. At the moment it seems that there is no ButtonBorderShape available that would behave like ConcentricRectangle. Is this intentional or is it expected that with upcoming beta versions we can also use the concentric style as button border shapes? Or is there maybe another way of getting the buttons shape to behave like a concentric shape? A use case I currently see is having the button as part of a container, using the .bordered button style and then aligning the corners of the button use the concentric style. Any information about this is highly appreciated. Thank you very much!
1
1
93
Jul ’25
UIViewControllerRepresentable breaks tab bar, ignores title and navigation items
In a UIKit-based project, I am attempting to integrate SwiftUI components. However, I encounter a persistent issue that hinders this integration. This problem arises when pushing a SwiftUI view using UIHostingController and subsequently attempting to push a UIKit view controller using UIViewControllerRepresentable. Not only are the navigation items and title from the view controller disregarded, but more concerningly, my tab bar item title is set to nil. This renders it impossible for me to utilize SwiftUI within my application when I wish to present older UIKit view controllers from there. This feedback has all the details and a sample project. FB18956999
1
1
124
Jul ’25
Pushing a UIHostingController has delayed toolbar items and title transitions
For over five years, this persistent issue has affected all platforms, and despite submitting numerous feedback reports, my concerns have remained unaddressed. When utilizing a UIHostingController within a UINavigationController, the toolbar items and title defined in the SwiftUI view manifest with a substantial delay. This delay is particularly noticeable with the introduction of Liquid Glass, resulting in a jarring transition. Although I had nearly lost hope, the issue was resolved in iOS 26 beta 3 when the push occurs from within a UISplitViewController. However, the problem persists outside of this context. Ultimately, this issue hinders my ability to develop high-quality applications and restricts my use of SwiftUI within my UIKit project for similar purposes. I sincerely hope that this issue can be resolved, enabling me to fully rely on SwiftUI in my project. Please prioritize this matter and make the necessary changes that were already made in UISplitViewController. This feedback has all the details and a sample project. FB14000542 Before the push: During the push: A second after the push finishes:
0
1
121
Jul ’25
The new navigationLinkIndicatorVisibility modifier crashes on < iOS 26
This new modifier is supposedly backported to iOS 17, but on attempting to use it on the latest iOS 18.5, this happens: Symbol not found: _$s7SwiftUI17EnvironmentValuesV33_navigationIndicatorVisibilityABIAA0G0OvpMV This happens with any usage of the modifier. An availability check won't save you either. The cruelest part of this is that I only need the modifier on iOS 26, lmao. Am I just missing something?
Topic: UI Frameworks SubTopic: SwiftUI
8
0
183
Jul ’25
TabView + NavigationStack + ScrollView navigationTitle bug
Hello there! I've been struggline with this thing for a two days now, and seems like it's a bug in SwiftUI. Navigation title is jumping on top of the ScrollView's content when switching tabs in TabView. Steps to reproduce: Scroll one tab to the bottom so that the large title is hidden and the floating toolbar appears. Go to another tab in the tab bar. Go back to the initial tab (it is still scrolled), and press the current tab button again to scroll to the top. The navigation title will glitch and be on top of the content. The animation fixes if you scroll again manually. Video: https://share.cleanshot.com/PFCSKMlH Code (simplified): import SwiftData import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { TabsContentView() } } } // ... struct TabsContentView: View { enum Tab { case library, profile } @State private var selectedTab: Tab = .library var body: some View { TabView(selection: $selectedTab) { NavigationStack { YourLibraryList() .navigationTitle("Your Library") } .tabItem { Label("Library", systemImage: "tray.fill") } .tag(Tab.library) NavigationStack { VStack { Spacer() Text("Profile") .font(.largeTitle) .foregroundColor(Color.theme.text) Text("Manage your account and preferences here") .font(.body) .foregroundColor(Color.theme.mutedForeground) .multilineTextAlignment(.center) .padding(.horizontal) Spacer() } .navigationTitle("Explore") } .tabItem { Label("Profile", systemImage: "person.fill") } .tag(Tab.profile) } .toolbarBackground(.ultraThinMaterial, for: .tabBar) .toolbarBackground(.visible, for: .tabBar) } } // ... struct YourLibraryList: View { var body: some View { ScrollView { VStack(spacing: 12) { ForEach(1 ... 20, id: \.self) { number in RoundedRectangle(cornerRadius: 12) .fill(Color.blue.opacity(0.1)) .stroke(Color.blue, lineWidth: 1) .frame(height: 60) .overlay( Text("\(number)") .font(.title2) .fontWeight(.semibold) .foregroundColor(.blue) ) } } .padding(.horizontal) } } }
2
0
202
Jul ’25
Unable to Drag 3D Model(Entity) in visionOS when UITextView Is in the Background
I'm running into an issue in Xcode when working on a visionOS app. Whenever I try to drag a 3D model entity in my scene, the drag gesture doesn't work if there's a UITextView (or SwiftUI TextEditor) in background of the 3D entity. It seems like the UITextView is intercepting the gesture or preventing the drag interaction from reaching the 3D content. Interestingly, when the 3D entity is placed infront of the ScrollView, the drag works as expected. Has anyone else experienced this behavior? Is this a known limitation or a bug in the current tooling? Any workarounds or fixes would be appreciated. Thanks!
0
0
132
Jul ’25
High CPU Usage in SwiftUI UIHostingController on iOS 26 Beta
Experiencing 100% CPU usage in SwiftUI app using UIHostingController, only on iOS 26 beta and Xcode beta. Issue involves excessive view updates in AttributeGraph propagation. Stack trace (main thread): thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0x00000001c38b9aa4 AttributeGraph`AG::Graph::propagate_dirty(AG::AttributeID) + 416 frame #1: 0x00000001d9a743ec SwiftUICore`SwiftUI.ObservationGraphMutation.apply() -> () + 656 frame #2: 0x00000001d97c0d4c SwiftUICore`function signature specialization <Arg[2] = [Closure Propagated : closure #1 () -> () in SwiftUI.(AsyncTransaction in _F9F204BD2F8DB167A76F17F3FB1B3335).apply() -> (), Argument Types : [SwiftUI.AsyncTransaction]> of generic specialization <()> of closure #1 () throws -> τ_0_0 in SwiftUI.withTransaction<τ_0_0>(SwiftUI.Transaction, () throws -> τ_0_0) throws -> τ_0_0 + 336 frame #3: 0x00000001d9a6ac80 SwiftUICore`merged function signature specialization <Arg[3] = Owned To Guaranteed> of function signature specialization <Arg[1] = [Closure Propagated : implicit closure #2 () -> () in implicit closure #1 @Sendable (SwiftUI.(AsyncTransaction in _F9F204BD2F8DB167A76F17F3FB1B3335)) -> () -> () in SwiftUI.GraphHost.flushTransactions() -> (), Argument Types : [SwiftUI.AsyncTransaction]> of SwiftUI.GraphHost.runTransaction(_: Swift.Optional<SwiftUI.Transaction>, do: () -> (), id: Swift.Optional<Swift.UInt32>) -> () + 196 frame #4: 0x00000001d9a52ab0 SwiftUICore`SwiftUI.GraphHost.flushTransactions() -> () + 176 frame #5: 0x00000001d8461aac SwiftUI`closure #1 (SwiftUI.GraphHost) -> () in SwiftUI._UIHostingView._renderForTest(interval: Swift.Double) -> () + 20 frame #6: 0x00000001d9bf3b38 SwiftUICore`partial apply forwarder for closure #1 (SwiftUI.ViewGraph) -> τ_1_0 in SwiftUI.ViewGraphRootValueUpdater.updateGraph<τ_0_0>(body: (SwiftUI.GraphHost) -> τ_1_0) -> τ_1_0 + 20 frame #7: 0x00000001d9e16dc4 SwiftUICore`SwiftUI.ViewGraphRootValueUpdater._updateViewGraph<τ_0_0>(body: (SwiftUI.ViewGraph) -> τ_1_0) -> Swift.Optional<τ_1_0> + 200 frame #8: 0x00000001d9e1546c SwiftUICore`SwiftUI.ViewGraphRootValueUpdater.updateGraph<τ_0_0>(body: (SwiftUI.GraphHost) -> τ_1_0) -> τ_1_0 + 136 frame #9: 0x00000001d8461a7c SwiftUI`closure #1 () -> () in closure #1 () -> () in closure #1 () -> () in SwiftUI._UIHostingView.beginTransaction() -> () + 144 frame #10: 0x00000001d846aed0 SwiftUI`partial apply forwarder for closure #1 () -> () in closure #1 () -> () in closure #1 () -> () in SwiftUI._UIHostingView.beginTransaction() -> () + 20 frame #11: 0x00000001d984f814 SwiftUICore`closure #1 () throws -> τ_0_0 in static SwiftUI.Update.ensure<τ_0_0>(() throws -> τ_0_0) throws -> τ_0_0 + 48 frame #12: 0x00000001d984e114 SwiftUICore`static SwiftUI.Update.ensure<τ_0_0>(() throws -> τ_0_0) throws -> τ_0_0 + 96 frame #13: 0x00000001d846aeac SwiftUI`partial apply forwarder for closure #1 () -> () in closure #1 () -> () in SwiftUI._UIHostingView.beginTransaction() -> () + 64 frame #14: 0x00000001851eab1c UIKitCore`___lldb_unnamed_symbol311742 + 20 * frame #15: 0x00000001852b56a8 UIKitCore`___lldb_unnamed_symbol315200 + 44 frame #16: 0x0000000185175120 UIKitCore`___lldb_unnamed_symbol308851 + 20 frame #17: 0x00000001d984e920 SwiftUICore`static SwiftUI.Update.dispatchImmediately<τ_0_0>(reason: Swift.Optional<SwiftUI.CustomEventTrace.ActionEventType.Reason>, _: () -> τ_0_0) -> τ_0_0 + 300 frame #18: 0x00000001d95a7428 SwiftUICore`static SwiftUI.ViewGraphHostUpdate.dispatchImmediately<τ_0_0>(() -> τ_0_0) -> τ_0_0 + 40 frame #19: 0x00000001852b59dc UIKitCore`___lldb_unnamed_symbol315204 + 192 frame #20: 0x00000001852b54a4 UIKitCore`___lldb_unnamed_symbol315199 + 64 frame #21: 0x0000000185745dd4 UIKitCore`_UIUpdateSequenceRunNext + 120 frame #22: 0x0000000186144fac UIKitCore`schedulerStepScheduledMainSectionContinue + 56 frame #23: 0x00000002505ad150 UpdateCycle`UC::DriverCore::continueProcessing() + 36 frame #24: 0x0000000180445b20 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 frame #25: 0x0000000180445a68 CoreFoundation`__CFRunLoopDoSource0 + 168 frame #26: 0x00000001804451f4 CoreFoundation`__CFRunLoopDoSources0 + 220 frame #27: 0x00000001804443a8 CoreFoundation`__CFRunLoopRun + 756 frame #28: 0x000000018043f458 CoreFoundation`_CFRunLoopRunSpecificWithOptions + 496 frame #29: 0x00000001928d19bc GraphicsServices`GSEventRunModal + 116 frame #30: 0x0000000186224480 UIKitCore`-[UIApplication _run] + 772 frame #31: 0x0000000186228650 UIKitCore`UIApplicationMain + 124 frame #32: 0x000000010bb1b504 MyApp.debug.dylib`main at main.swift:13:1 frame #33: 0x00000001043813d0 dyld_sim`start_sim + 20 frame #34: 0x000000010468ab98 dyld`start + 6076 Used let _ = Self.printChanges() in my SwiftUI View and got infinite changes of \_UICornerProvider.<computed 0x000000018527ffd8 (Optional<UICoordinateSpace>)> changed. Reproduces only on beta; works on stable iOS. Likely beta-specific bug in SwiftUI rendering.
7
1
313
Jul ’25
Recommended / Canonical way to host remote (separate process) SwiftUI views.
I am building a tool that enables the user to write, auto-compile and interact with SwiftUI code (think something like a mini Xcode Canvas). Which so far works really well. The app is not sandboxed since it uses tools like swiftc and sourcekit-lsp. The obvious problem here is that since the 'Preview' part of the app is driven by arbitrary code a crash/hang there would lead to a termination of the whole app. I understand that there are some private apis like NSRemoteView or CALayerHost but I would like to avoid them if I can. From what I see reading other similar solutions IOSurface sharing + event forwarding might be the best solution. So my question is: Is there a proper or recommended way to achieve this? Meaning having a fully interactive SwiftUI view presented in my host app but running on a separate process? Any pointers to the right direction or examples or whatever could help me with this would be greatly appreciated.
4
0
164
Jul ’25