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

Posts under SwiftUI tag

200 Posts

Post

Replies

Boosts

Views

Activity

Xcode forces my Macbook to restart when previewing canvas
I can't use Xcode without it crashing. Just writing a very simple iOS app with SwiftUI (using only forms and sections). Whenever my canvas updates to correspond to my changes it forces my Macbook to restart. Does anyone have a solution for this. I'll be honest it's becoming really frustrating. Thank you. Macbook M3 Pro 16GB ram, 500gb Space (400gb free space)
1
0
93
Aug ’25
Liquid Glass clear variant
In this WWDC talk about liquid glass https://developer.apple.com/videos/play/wwdc2025/219/ they mention that there are two variants of liquid glass, regular and clear. I don't see any way to try the clear variant using the .glassEffect() APIs, they only expose regular, is there some other way to try the clear variant?
5
2
405
Aug ’25
iPadOS 26 Menu Bar - Hiding Unused Menu Items
How to Hide Unused Menu Items on iPadOS Menu Bar in SwiftUI? (Xcode 26 beta 4, iPadOS 26 beta 4) We’re working on adding menu bar support to our SwiftUI app on iPadOS, aiming to provide a more consistent and productive experience across platforms. We’d like to hide system-provided menu items that aren’t relevant to our app, such as: Open… Select All Customize Toolbar… New Window, Show All Windows, Open Windows, etc. Is there a way to control which default items appear in the menu bar? Feedback ID: FB18792279
0
0
148
Aug ’25
iPadOS 26 Menu Bar - Undo / Redo
How to Enable or Customize Undo/Redo Menu Items on iPadOS Menu Bar in SwiftUI? (Xcode 26 beta 4, iPadOS 26 beta 4) We’re working on adding menu bar support to our SwiftUI app on iPadOS, aiming to provide a more consistent and productive experience across platforms. Our app is a unified iPad/macOS app that uses UndoManager to support undo/redo operations. However, we’ve run into the following issues: On macOS, undo and redo work as expected via the menu bar. On iPadOS, the Undo and Redo menu items are always disabled, even though the functionality works within the app. We also explored the possibility of hiding the system-generated Undo/Redo menu items so we could provide custom implementations—but couldn’t find a way to remove or override them. Question: Is there a recommended approach to enable or customize the Undo/Redo menu bar items on iPadOS using SwiftUI? Any suggestions or insights would be greatly appreciated! Feedback ID: FB18792279
0
1
112
Aug ’25
.contentMargins(.top, 0, for: .scrollContent) has no effect on .plain List with section headers (iOS 17 & 18)
I'm trying to remove the extra top padding from the first section of a SwiftUI List using .plain style. I applied: .contentMargins(.top, 0, for: .scrollContent) But it seems to have no effect on iOS 17 and iOS 18.5 when section headers are present. However, it does work correctly on iOS 26 (tested with the latest Xcode beta). Has anyone else run into this? Is this a known issue or regression in iOS 17/18? Is there any reliable workaround to remove or reduce the top padding in .plain list style when using section headers? I have screenshots comparing iOS 18.5 and iOS 26 if needed. Thanks in advance!
1
0
93
Aug ’25
NavigationSplitView content column renders list in plain style – even on iPhone
Hi everyone, I’m building an iOS app that originally targeted iPhone using NavigationStack. Now I’m adapting it for iPad and switched to using NavigationSplitView to support a three-column layout. The structure looks like this: NavigationSplitView { A // Sidebar } content: { B // Middle column – this shows a list } detail: { C // Detail view } The issue is with the list shown in view B (the content column). It appears completely unstyled, as if it’s using .listStyle(.plain) — with no background material, no grouped sections, and a very flat look. I can understand that this might be intentional on iPad to visually distinguish the three columns. However, the problem is that this same unstyled list also appears on iPhone, even though iPhone only shows a single column view at a time! I tried explicitly setting .listStyle(.insetGrouped) or .listStyle(.grouped) on the list in view B, but it makes no difference. When I go back to NavigationStack, the list in B is styled properly, just as expected — but then I lose the enhanced iPad layout. What I’m looking for: I’d like to keep using NavigationSplitView, but I want the list in the content column (view B) to use the default iOS list styling, at least on iPhone. Is there any way to achieve this? Thanks!
0
0
73
Aug ’25
How to keep bottom toolbar pinned, when sheet's detent are changed in code
I am trying to add a pinned(always visible and not moving) toolbar to the bottom of UISheetPresentationController or presentationDetent. This is achievable when the user is dragging to change the size of the sheet. But when changing the detent by code, it does not work. For example, when changing from medium to large, the ViewController's size is changed to large then moved up to the position. From the user's POV, anything at the bottom to disappear for a few frames then reappears. From my testing, when using UISheetPresentationController, ViewController only knows the medium and large state's frame and bounds, so manually setting it up won't work. Is there a way to keep views at the bottom always visible in this case? The sample code below is in SwiftUI for easy recreation, and the responses can be in UIKit. Sample Code: struct ContentView: View { @State var showSheet: Bool = true @State var detent: PresentationDetent = .medium var body: some View { EmptyView() .sheet(isPresented: $showSheet) { ScrollView { } .safeAreaInset(edge: .bottom) { Button { detent = (detent == .medium) ? .large : .medium } label: { Text("Change Size") } .buttonStyle(.borderedProminent) .presentationDetents([.medium, .large], selection: $detent) .presentationBackgroundInteraction(.enabled) } } } }
1
0
114
Aug ’25
Scroll to Top gesture breaks when setting List or ScrollView background
When a ScrollView or List is nested in a TabView, you can press on the tab button and the scroll view will scroll to top. import SwiftUI struct SwiftUIView: View { let items = (1...100).map { "Item \($0)" } var body: some View { TabView { Tab("home", systemImage: "house") { ScrollView { ForEach(items, id: \.self) { item in Text(item) .frame(maxWidth: .infinity, alignment: .center) } } } } } } #Preview { SwiftUIView() } But if we add a background to the ScrollView, the scroll to top gesture breaks. import SwiftUI struct SwiftUIView: View { let items = (1...100).map { "Item \($0)" } var body: some View { TabView { Tab("home", systemImage: "house") { ScrollView { ForEach(items, id: \.self) { item in Text(item) .frame(maxWidth: .infinity, alignment: .center) } } // Set background on ScrollView. .background(Color.red) } } } } #Preview { SwiftUIView() } I made a similar post on StackOverflow, but haven't been able to find a proper solution. This feels like a bug of some sort in SwiftUI.
1
2
263
Aug ’25
Unexpected bundle class 16 declaring type public.gpx
I have a minimal macOS document based app written in SwiftUI in Xcode 16.3. It is created from the standard template replacing all occurences of 'com.example.plain-text' with 'com.topografix.gpx' and changing the file extension in info.plist from 'exampletext' to 'gpx'. Those changes are sufficient to allow opening, editing and saving of .gpx files. However, when opening, editing or saving, the following message is written to the console 6 times. Unexpected bundle class 16 declaring type public.gpx While this is not preventing the app from working, I would like to understand the origin of the message and fix the underlying problem.
1
0
216
Aug ’25
Animate colours in a SwiftUI Canvas
Pseudo-code: PhaseAnimator([false,true], trigger: foo) { flash in ZStack { Capsule() .foregroundStyle(flash ? .red : .green) Canvas { context, size in context.draw(image: Image(name: "foo"), toFitRect: some_rectangle); context.draw(text: Text("foo"), toFitRect: another_rectangle); } .foregroundStyle(flash ? .black : .white) } } animation: { flash in return .linear(duration: 0.5); } The Capsule's colour animates, but the Canvas's doesn't. The Canvas drawing code is only ever called with flash==false. What do I have to do to the Canvas so that it redraws with the intermediate colours during the animation?
3
0
381
Aug ’25
VoiceOver doesn't work for AVRoutePickerView wrapped in UIViewRepresentable
Hi, I've wrapped AVRoutePickerView in SwiftUI using pretty much the code given here, with a few changes: func makeUIView(context: Context) -> UIView { let routePickerView = AVRoutePickerView() // Configure the button's color. //routePickerView.delegate = context.coordinator //routePickerView.backgroundColor = .secondarySystemBackground routePickerView.tintColor = .accent routePickerView.activeTintColor = .accent // Indicate whether your app prefers video content. routePickerView.prioritizesVideoDevices = false return routePickerView } I commented out routePickerView.delegate = context.coordinator because it doesn't compile; context.coordinator is of type Void and I'm not sure how to fix that. I'm not sure if that has anything to do with the issue. Anyway, this works fine without VoiceOver; if I tap the button, I get the AirPlay popover. But in VoiceOver, if I select the button and double-tap, nothing happens… it just reads the button's accessibilityLabel again. How can I get the AirPlay popover to show in VoiceOver?
3
0
385
Aug ’25
When removing a ToolbarItem from the navigation bar, how do I make the remaining ToolbarItems resize correctly?
Because .searchable does not allow for customizing buttons in the search bar, I've manually had to recreate the search bar as shown below. However, when removing one of the items in the search bar, the TextField does not resize correctly and effectively inserts padding on the leading edge. When the TextField is focused, it resizes and fills the entire space. If the "Compose" button was already hidden when the search bar is presented, it lays out correctly. How do I resize the TextField after removing the "Compose" button automatically? Thanks, jjp struct ContentView: View { @State var isSearchBarVisible = false @State var isComposingMessage = false @State var searchText = "" let items: [String] = ["hey", "there", "how", "are", "you"] var searchItems: [String] { items.filter { item in item.lowercased().contains(searchText.lowercased()) } } var body: some View { NavigationStack { VStack { List { if !searchText.isEmpty { ForEach(searchItems, id: \.self) { item in Text(item) } } else { ForEach(items, id: \.self) { item in Text(item) } } } } .toolbar { if isSearchBarVisible { ToolbarItem(placement: .principal) { TextField("Search", text: $searchText) .padding(8) .background(Color.gray.opacity(0.2)) } ToolbarItem(placement: .topBarTrailing) { Button(action: { isSearchBarVisible = false },[![enter image description here][1]][1] label: { Text("Cancel") }) } if !isComposingMessage { ToolbarItem(placement: .topBarTrailing) { Button(action: { isComposingMessage.toggle() }, label: { Text("Compose") }) } } } else { ToolbarItem(placement: .topBarLeading) { Button(action: { isSearchBarVisible = true }, label: { Text("Search") }) } ToolbarItem(placement: .principal) { Text("Title") } ToolbarItem(placement: .topBarTrailing) { Button(action: { isComposingMessage.toggle() }, label: { Text("Compose") }) } } } } } }
1
0
107
Aug ’25
SwiftUI Navigation - Top toolbar breaks and app is unusable
We've been trying to track down a non-reproducible issue for the past few months, and I'm wondering if anybody has encountered the same one. Screenshots of the issue attached here. As you can see, the toolbar isn't respecting the safe area; there are many more issues that occur when this bug happens as well, such as the app being extremely laggy and sheets not opening. Anecdotally, this seems to happen if the app is opened after not having been opened in a while (say, a day or so). It tends to happen first thing in the morning when I open the app, but as I mentioned, it's been very hard to reproduce. I'm also wondering if it's a known SwiftUI navigation issue or if anyone has encountered this.
2
0
119
Jul ’25
Tinting/Coloring tabs when using SidebarAdaptableTabViewStyle like List
SwiftUI.List allows for customization using .listItemTint, .tint, or .foregroundStyle. This can be used to color individual items in the list, other than the app's specified accent color. Is there an equivalent feature to customize individual Tab's icon or label, when using TabView's SidebarAdaptableTabViewStyle, and its in the sidebar style. From what I understand, there needs to be a modifier applied directly to Tab unlike List, and not just the label. Since there isn't any color/tint modifiers, is it not possible?
1
0
74
Jul ’25
NavigationSplitView not fully supported on smaller (SE) iPhones
My SwiftUI code runs fine on macOS, iOS(iPad) and larger iPhones, but will not display the detail view on smaller iPhones. Is there a way to force the smaller iPhones to display the detail view? And if not, When I put the App on the Apple store, for sale, will the Apple store be smart enough to flag the App as not appropriate for smaller iPhones, such as the SE (2nd and 3rd gen.) and prevent downloads? Thanks in advance for any guidance.
6
0
1.1k
Jul ’25
UISearchBar .minimal no background when compiled on Xcode 26
When compiled on Xcode 16.4.0: When compiled on Xcode 26: The code: import SwiftUI struct SearchBarController: UIViewRepresentable { @Binding var text: String var placeholderText: String class Coordinator: NSObject, UISearchBarDelegate { @Binding var text: String init(text: Binding<String>) { _text = text } func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { text = searchText } } func makeUIView(context: Context) -> UISearchBar { let searchBar = UISearchBar(frame: .zero) searchBar.delegate = context.coordinator searchBar.placeholder = placeholderText searchBar.searchBarStyle = .minimal return searchBar } func updateUIView(_ uiView: UISearchBar, context: Context) { uiView.text = text } func makeCoordinator() -> SearchBarController.Coordinator { return Coordinator(text: $text) } }
3
0
153
Jul ’25
UICollectionViewDataSourcePrefetching does not work on SwiftUI wrapped VisionOS
prefetching logic for UICollectionView on VisionOS does not work. I have set up a Standalone test repo to demonstrate this issue. This repo is basically a visionOS version of Apple's guide project on implementation of prefetching logic. in repo you will see a simple ViewController that has UICollectionView, wrapped inside UIViewControllerRepresentable. on scroll, it should print 🕊️ prefetch start on console to demonstrate func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) is called. However it never happens on VisionOS devices. With the same code it behaves correctly on iOS devices
1
0
159
Jul ’25
Context menus need option to disable morphing
For some controls it is desirable to not use the morphing transition when presenting a Menu. Instead, you might want to have the old behavior, where the menu is presented above or below the initiating view. This can be the case for any other control than toolbar items, but especially for bigger content cards, that should trigger a menu upon tapping it once. In those cases it looks weird and does not really help to keep context of what the action is doing. Is there some way to do this right now? In case it's not, I also filed a feedback. FB18413055
0
0
83
Jul ’25
What to do about the new glass medium detent sheets
So many issues with the new sheet design, I don't think I can ship these. And it's both in UIKit and SwiftUI. Honestly these net sheets seem like a failure from start to finish and I don't believe it will get better for the initial release. Toolbar buttons in medium detent size have very low contrast and look bad with their opaque appearance During the transition from medium to large detent the whole sheet flickers and turns transparent for a split moment, creating a very jarring transition (video here: https://mastodon.social/@nicoreese/114938826906689965). In the large detent the background is always white in light mode making the cells bleed into the background making them indistinguishable from it. I should be able to set a background color for the large detent which smoothly transitions to it. Like: glass in medium and system grouped background in large. Any interaction with the medium detent sheet makes it scale up. Why? It's okay for single interactions but not for when the user taps something in it rapidly. There needs to be a way to disable this behavior. In the medium detent List/UICollectionView rows are white in light mode or gray in dark mode. Especially in dark mode it looks very bad against the glass background. Those rows should probably be translucent to better fit the glass. This needs serious fixing and fast. FB18919680 FB18919657 FB18919600 FB18919549 FB18919496 FB18919630
0
1
106
Jul ’25