Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

Zooming between SwiftUI and Storyboards
This is probably abusing the system more than it should be but maybe it is somehow possible. I have: An objective-C based storyboard iPad OS app. I'm beginning to adopt SwiftUI. I have a hosting controller with a content view that has a lazygrid of cards, which have an NSManagedObject for data. On tapping a card, a detail view opens, if in multi-tasking, a new window, if not, pushing the navigation controller (this detail view still exists in UIKit/ObjC, and is handled by sending a notification with the ObjectID, which then triggers a storyboard segue to the detail.) I have zoom transitions on all my things. They work great in Obj.C, especially now with the bar button source. On my iPhone target, I still have an old tableview, and I'm able to zoom properly - if someone changes the detail view's managed object (through a history menu), the zoom context looks up where the tableview is, and scrolls to it while popping. I'd like to somehow do this on the lazygrid - first) to just have an individual card be the zoom source, it should be able to know what the source view is to say in the prepareForSegue method just to zoom at all. and second) if the detail has changed the current ObjectID (which gets passed around as a notification), to somehow scroll the lazygrid to the right object before popping. I've looked at https://developer.apple.com/tutorials/SwiftUI/interfacing-with-uikit but this seems like swiftUI is the host. I have it the other way around, uikit hosting swiftUI pushing uikit. TIA for any pointers
1
0
80
2w
UIGraphicsImageRenderer display blank image with iOS 26
Hello, First of all, I've already made a bug report here : https://feedbackassistant.apple.com/feedback/19731998 I'm facing a problem while using UIGraphicsImageRenderer to create an image, that is use to create a UIColor with a pattern via UIColor(patternImage:). It's well displayed for iOS 18.2 and lower, whereas the whole color is blank with iOS 26. -> Please find a sample project linked to the bug report ViewController.swift post that illustrates the issue, in the ViewController.swift file. I'll also link screenshots of the sample app, one built with iOS 18.2 and another with iOS 26.0. Reproduction steps : I create an image with UIGraphicsImageRenderer : let image = UIGraphicsImageRenderer().image { context in // Do anything here } Then I use this image to create a UIColor : UIColor(patternImage: image) I apply this color to the fillColor of a CAShapeLayer : shapeLayer.fillColor = UIColor(patternImage: image) Expected result : Run on iOS 26 and lower and the layer filled with the pattern color is correctly displayed, as it is on iOS 18.2 and lower. Observed result : Run on iOS 26 and the layer is filled with a blank/white color instead of the intended pattern color. Has anyone been facing the problem ? Thanks, Thibault Poujat
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
60
2w
On macOS, what is the appropriate way to disable the sidebar material in a NavigationSplitView?
If you create a NavigationSplitView, then the sidebar is automatically adorned with a sidebar material effect. This affects the views background as well as any controls that are in the view. What is the correct way to disable this behaviour so that I can use a NavigationSplitView without the material effects being applied? The best I've come up with so far is to explicitly set the background on the sidebar but I'm curious if that's the correct way or I'm just getting lucky. struct ContentView: View { var body: some View { NavigationSplitView { // This works, but is it correct? SidebarView() .background(.windowBackground) } detail: { DetailView() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
4
0
118
2w
Change to safe area logic on iOS 26
I have a few view controllers in a large UIKit application that previously started showing content right below the bottom of the top navigation toolbar. When testing the same code on iOS 26, these same views have their content extend under the navigation bar and toolbar. I was able to fix it with: if #available(iOS 26, *, *) { self.edgesForExtendedLayout = [.bottom] } when running on iOS 26. I also fixed one or two places where the main view was anchored to self.view.topAnchor instead of self.view.safeAreaLayoutGuide.topAnchor. Although this seems to work, I wonder if this was an intended change in iOS 26 or just a temporary bug in the beta that will be resolved. Were changes made to the safe area and edgesForExtendedLayout logic in iOS 26? If so, is there a place I can see what the specific changes were, so I know my code is handling it properly? Thanks!
Topic: UI Frameworks SubTopic: UIKit
3
2
347
2w
Toolbar tint color with Liquid Glass
I'm adapting a UIKit app to work with Liquid Glass. In pre-Liquid Glass days, the application window had a tintColor that was passed down to all of its descendant views, resulting in toolbar buttons that match the app's color scheme. In iOS 26, my toolbar buttons are always black, no matter what. I've tried setting the UIBarButtonItem#tintColor on the button and setting UIBarButtonAppearanc#tintColor. The buttons are still black. What am I doing wrong? I see a tintColor modifier for SwiftUI toolbar buttons, so it seems like maybe you can do this with SwiftUI. Many of the built-in apps on iOS 26 beta have only black toolbar buttons - is it not possible to change the toolbar button tint color on iOS 26?
Topic: UI Frameworks SubTopic: General
1
0
271
2w
In SwiftUI for macOS, how can you detect if a view or any ancestor is "hidden"?
Given a View in SwiftUI for macOS, how can I tell if that view is hidden either because it, or any of its ancestor's opacity is 0.0 or the .hidden modifier has been applied? Presumably I can manually do this with an Environment value on the ancestor view, but I'm curious if this can be done more idiomatically. An example use case: I have views that run long-running Tasks via the .task(id:) modifier. These tasks only need to be running if the View itself is visible to the user. When the View is hidden, the task should stop. When the View reappears, the Task should restart. This happens automatically when Views are created and destroyed, but does not happen when a view is only hidden.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2
0
78
2w
How do you compute backing pixel alignment in SwiftUI's `Layout`?
When performing custom layout in AppKit, it's essential that you pixel align frames using methods like backingAlignedRect. The alignment differs depending on the backingScaleFactor of the parent window. When building custom Layouts in SwiftUI, how should you compute the alignment of a subview.frame in placeSubviews() before calling subview.place(...)? Surprisingly, I haven't seen any mention of this in the WWDC videos. However, if I create a Rectangle of width 1px and then position it on fractional coordinates, I get a blurry view, as I would expect. Rounding to whole numbers works, but on Retina screens you should be able to round to 0.5 as well. func placeSubviews( in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout Void ) { // This should be backing aligned based on the parent window's backing scale factor. var frame = CGRect( x: 10.3, y: 10.8, width: 300.6, height: 300.1 ) subview.place( at: frame.origin, anchor: .topLeading, proposal: ProposedViewSize(frame.size) ) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1
0
50
2w
TabView with NavigationStack issue on macOS Tahoe Beta 7
I have an app using TabView with multiple Tabs using tabViewStyle „sidebarAdaptable“. Each Tab does have its own NavigationStack. When I switch multiple times between the tabs and append a child view to one of my navigation stacks, it will stop working after a few tries with the following error „A NavigationLink is presenting a value of type “HomeStack” but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated. Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView.“ The same code is working fine on iOS, iPadOS but not working on macOS. When I remove tabViewStyle of sidebarAdaptable it’s also working on macOS. I shrinked it down to a minimal reproducible code sample. Any idea if that is a bug or I'm doing something wrong? struct ContentView: View { @State private var appState: AppState = .init() var body: some View { TabView(selection: $appState.rootTab) { Tab("Home", systemImage: "house", value: RootTab.home) { NavigationStack(path: $appState.homeStack) { Text("Home Stack") NavigationLink("Item 1", value: HomeStack.item1) .padding() NavigationLink("Item 2", value: HomeStack.item2) .padding() .navigationDestination(for: HomeStack.self) { stack in Text("Stack \(stack.rawValue)") } .navigationTitle("HomeStack") } } Tab("Tab1", systemImage: "gear", value: RootTab.tab1) { NavigationStack(path: $appState.tab1Stack) { Text("Tab 1 Stack") NavigationLink("Item 1", value: Tab1Stack.item1) .padding() NavigationLink("Item 2", value: Tab1Stack.item2) .padding() .navigationDestination(for: Tab1Stack.self) { stack in Text("Stack \(stack.rawValue)") } .navigationTitle("Tab1Stack") } } } .tabViewStyle(.sidebarAdaptable) .onChange(of: appState.rootTab) { _, _ in appState.homeStack.removeAll() appState.tab1Stack.removeAll() } } } @MainActor @Observable class AppState { var rootTab: RootTab = .home var homeStack: [HomeStack] = [] var tab1Stack: [Tab1Stack] = [] } enum RootTab: Hashable { case home case tab1 case tab2 } enum HomeStack: String, Hashable { case home case item1 case item2 } enum Tab1Stack: String, Hashable { case home case item1 case item2 }
0
0
65
2w
iOS 26 (beta 7) setting .searchFocused programmatically does not work
Already filed a feedback in case this is a bug, but posting here in case I'm doing something wrong? I'd like the search field to automatically be displayed with the keyboard up when the view appears. This sample code works in iOS 18, but it does not work in iOS 26 beta 7 I also tried adding a delay to setting searchIsFocused = true but that did not help struct ContentView: View { var body: some View { NavigationStack { NavigationLink(destination: ListView()) { Label("Go to list", systemImage: "list.bullet") } } .ignoresSafeArea() } } struct ListView: View { @State private var searchText: String = "" @State private var searchIsPresented: Bool = false @FocusState private var searchIsFocused: Bool var body: some View { ScrollView { Text("Test") } .searchable(text: $searchText, isPresented: $searchIsPresented, placement: .automatic, prompt: "Search") .searchFocused($searchIsFocused) .onAppear { searchIsFocused = true } } }
1
0
53
2w
Force a locale from string catalog
I'm writing an iOS app that shares content with buddies. So my app will run in one language but the shared content will use the locale configured for the buddy. I found this Apple documentation which suggests that locale: (Locale(identifier: is the solution. Apple Documentation But I can't get it to work. Here's sample code. struct LocalizationDemoView: View { @State var isEnglish = true var body: some View { var myLocale: String { isEnglish ? "en": "de" } VStack { Toggle("Switch language", isOn: $isEnglish).frame(maxWidth: 200) HStack { Text("\(myLocale): ") Text(String(localized: "Hello world!", locale: (Locale(identifier: myLocale)), comment: "To share")) } } } } And here's the excerpt from the string catalog: { "sourceLanguage" : "en", "strings" : { "Hello world!" : { "comment" : "To share", "localizations" : { "de" : { "stringUnit" : { "state" : "translated", "value" : "🇩🇪 Moin Welt!" } }, "en" : { "stringUnit" : { "state" : "translated", "value" : "🇬🇧 Hello world!" } } } } } } Has Apple reduced support for string catalogs or is my code wrong? Xcode 16.4 compiled on MacOS 15.6.1, device iOS 18.6.2
4
0
200
2w
Seeing some behaviour in Swift that I don't understand...
It's related to the passByValue nature of structs. In the sample code below, I'm displaying a list of structs (and I can add instances to my list using Int.random(1..<3) to pick one of two possible predefined versions of the struct). I also have a detail view that can modify the details of a single struct. However when I run this code, it will instead modify all the instances (ie either Sunday or Monday) in my list. To see this behaviour, run the following code and: tap New Trigger enough times that there are multiple of at least one of the sunday/monday triggers tap one of the matching trigger rows modify either the day, or the int expected: only one of the rows will reflect the edit actual: all the matching instances will be updated. This suggests to me that my Sunday and Monday static instances are being passed by reference when they get added to the array. But I had thought structs were strictly pass by value. What am I missing? thanks in advance for any wisdom, Mike struct ContentView: View { @State var fetchTriggers: [FetchTrigger] = [] var body: some View { NavigationView { VStack { Button("New Trigger") { fetchTriggers.append(Int.random(in: 1..<3) == 1 ? .sunMorning : .monEvening) } List($fetchTriggers) { fetchTrigger in NavigationLink(destination: FetchTriggerDetailView(fetchTrigger: fetchTrigger) .navigationBarTitle("Back", displayMode: .inline)) { Text(fetchTrigger.wrappedValue.description) .padding() } } } } } } struct FetchTrigger: Identifiable { static let monEvening: FetchTrigger = .init(dayOfWeek: .monday, hour: 6) static let sunMorning: FetchTrigger = .init(dayOfWeek: .sunday, hour: 3) let id = UUID() enum DayOfWeek: Int, Codable, CaseIterable, Identifiable { var id: Int { self.rawValue } case sunday = 1 case monday case tuesday var description: String { switch self { case .sunday: return "Sunday" case .monday: return "Monday" case .tuesday: return "Tuesday" } } } var dayOfWeek: DayOfWeek var hour: Int var description: String { "\(dayOfWeek.description), \(hour):00" } } struct FetchTriggerDetailView: View { @Binding var fetchTrigger: FetchTrigger var body: some View { HStack { Picker("", selection: $fetchTrigger.dayOfWeek) { ForEach(FetchTrigger.DayOfWeek.allCases) { dayOfWeek in Text(dayOfWeek.description) .tag(dayOfWeek) } } Picker("", selection: $fetchTrigger.hour) { ForEach(1...12, id: \.self) { number in Text("\(number)") .tag(number) } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1
0
181
2w
Squicle app icons on macOS 26
Just posted this feedback regarding macOS 26 "Tahoe" (FB19853155) - please support with additional submissions if you share my view. I will miss the beautiful and individual designed icons of the past! "macOS 26 is enforcing squicles for app icons, falling back to a grey background for 3rd party apps without a compliant AppIcon asset. As a result many original app icons are reduced in size and hard to distinguish because they share the same background color. Although I respect Apple's strive for an iOS-like UI on Macs, a smooth transition path would be more user- and developer-friendly ... e.g. with some info.plist property to opt-out icon migration, potentially ignored by a future macOS version. The current solution causes a bad usability, and makes the system look inconsistent as many - especially free - software will not be updated with new icon designs. Please reconsider this bad design decision!"
1
1
170
2w
Menu view flashes white before closing when device is set to dark appearance
Feedback ID: FB19846667 When dismissing a Menu view when the device is set to dark appearance, there is a flash of lightness that is distracting and feels unnatural. This becomes an issue for apps that rely on the user interacting with Menu views often. When using the overflow menu on a toolbar, the effect of dismissing the menu is a lot more natural and there is less flashing. I expect a similar visual effect when creating Menu views outside of a toolbar. Has anyone found a way around this somehow? Comparison between dismissing a menu and a toolbar overflow: https://www.youtube.com/shorts/H2gUQOwos3Y Slowed down version of dismissing a menu with a visible light flash: https://www.youtube.com/shorts/MBCCkK-GfqY
0
0
129
2w
iOS 26 @FocusState Doesn't Work If TextField Is In Toolbar
When I add a TextField with @FocusState to a toolbar, I noticed that setting focus = false doesn't cause the form to lose focus If I move the TextField out of the toolbar setting focus = false works fine. How can I unfocus the text field when the cancel button is tapped? Minimal example tested on Xcode Version 26.0 beta 6 (17A5305f): import SwiftUI struct ContentView: View { @State private var text: String = "" @FocusState private var focus: Bool var body: some View { NavigationStack { List { Text("Test List") } .toolbar { ToolbarItem(placement: .bottomBar) { TextField("Test", text: $text) .padding(.horizontal) .focused($focus) } ToolbarItem(placement: .bottomBar) { Button(role: .cancel) { focus = false // THIS DOESN'T WORK! } } } } } } #Preview { ContentView() }```
0
1
180
2w
iOS 26 (beta) Nav Bar Item Image Insets bug
I've noticed that in iOS 26, Navigation Bar Items' Image Insets parameters as set in Xcode are not being read correctly. Specifically, it appears that on iOS 26 beta, negative inset numbers are being read as positive. Feedback report FB19838333 includes a sample project demonstrating this bug.
0
0
143
2w
How do you observe the count of records in a Swift Data relationship?
What is the correct way to track the number of items in a relationship using SwiftData and SwiftUI? Imagine a macOS application with a sidebar that lists Folders and Tags. An Item can belong to a Folder and have many Tags. In the sidebar, I want to show the name of the Folder or Tag along with the number of Items in it. I feel like I'm missing something obvious within SwiftData to wire this up such that my SwiftUI views correctly updated whenever the underlying modelContext is updated. // The basic schema @Model final class Item { var name = "Untitled Item" var folder: Folder? = nil var tags: [Tag] = [] } @Model final class Folder { var name = "Untitled Folder" var items: [Item] = [] } @Model final class Tag { var name = "Untitled Tag" var items: [Item] = [] } // A SwiftUI view to show a Folder. struct FolderRowView: View { let folder: Folder // Should I use an @Query here?? // @Query var items: [Item] var body: some View { HStack { Text(folder.name) Spacer() Text(folder.items.count.formatted()) } } } The above code works, once, but if I then add a new Item to that Folder, then this SwiftUI view does not update. I can make it work if I use an @Query with an #Predicate but even then I'm not quite sure how the #Predicate is supposed to be written. (And it seems excessive to have an @Query on every single row, given how many there could be.) struct FolderView: View { @Query private var items: [Item] private var folder: Folder init(folder: Folder) { self.folder = folder // I've read online that this needs to be captured outside the Predicate? let identifier = folder.persistentModelID _items = Query(filter: #Predicate { link in // Is this syntax correct? The results seem inconsistent in my app... if let folder = link.folder { return folder.persistentModelID == identifier } else { return false } }) } var body: some View { HStack { Text(folder.name) Spacer() // This mostly works. Text(links.count.formatted()) } } } As I try to integrate SwiftData and SwiftUI into a traditional macOS app with a sidebar, content view and inspector I'm finding it challenging to understand how to wire everything up. In this particular example, tracking the count, is there a "correct" way to handle this?
1
0
111
2w
Compositional Layout's broken `visibleItemsInvalidationHandler`
Hello everybody! TLDR: Issues with visibleItemsInvalidationHandler. Minimal code to reproduce available. I've been working with Compositional Layout for a while now and recently I've found myself needing to implement custom animation based on scroll position of UI elements. Once I found visibleItemsInvalidationHandler it felt like the exact solution that I needed. Once I implement I've found out it doesn't quite behave as you'd expect. To put it simply, it seems like the animations only work if your whole layout does not use .estimated nor .uniformAcrossSiblings. As soon as you use them then the animations will stop working, I've debugged it deeper and it seems like the invalidation context generated by it does not include the indexPath of the cells, which is always included in the version in which it works. Feel free to swap the line 51 with its comment to flip between the working and failing version of it. Playground Example My final question therefore is... Is this the expected behavior? The documentation doesn't give any clues about such behavior and although I've tried relentlessly to find a workaround for this specific hiccup I was not successful with it.
1
0
102
2w