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

Variable modification in forEach
Hi! I'm trying to do a forEach loop on an array of objects. Here's my code : ForEach($individus) { $individu in if individu.reussite == true { individu.score -= 10 } else { individu.score = (individu.levees * 10) + 20 + individu.score } } I have an error on the code in the 'if' saying that "Type '()' cannot conform to 'View'", but I have no idea on how solving this problem.
Topic: UI Frameworks SubTopic: SwiftUI
2
0
258
Jan ’25
Apple Maps annotations and markers
In Apple's Maps app, an annotation is made up of a circle shape or rounded rectangles with a glyph-image. When selecting an annotation, the annotation animates into a balloon marker (see attached GIF). How does Apple Maps solve this - from custom annotation to balloon marker with spring animation? I switched my Maps implementation from SwiftUI to UIKit with a UIViewRepresentable to support annotation clustering - and it works beautifully. But how to subclass an MKAnnotationView (or MKMarkerAnnotationView <- the balloon) to enable selection and animation as in Apple Maps? MKMarkerAnnotationView only show balloon markers and I tried everything inside MKAnnotationView (CALayer, etc.)
1
0
410
Feb ’25
Bug in iOS 18 with NSTimeZone and DatePicker
iOS 18 broke some functionality in my Objective-C app with regard to using the DatePicker. The key lines are as follows: datePicker.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:timezoneOffset]; datePicker.date = [NSDate date]; When timezoneOffset is -29380, the value for San Francisco, the Date Picker is a whole MONTH off. It shows November instead of December. But when it is -29359, the value for Seattle, which is in the same time zone (PST), it shows the correct month. In fact, even towns surrounding San Francisco usually return the correct value. Some other cities in other time zones also cause the Date Picker to be a month off.
7
0
761
Jan ’25
How to solve "Extra trailing closure passed in call" in a section?
Hey there, I'm new to Swift and currently building my first app. I'm having the error "Extra trailing closure passed in call" in a section and already compared it to working sections and just can't find the error in my code. Maybe you guys can help me: Form { Section("Essential Information") { TextField("Title", text: $title) TextField("Composer", text: $composer) TextField("Opus", text: $opus) } The error is occurring in the section line. There are over sections that work perfectly fine: Section("Additional Details") { TextField("Epoch", text: $epoch) TextField("Type", text: $type) TextField("Accompaniment", text: $accompaniment) TextField("Length (minutes)", value: $length, format: .number) .keyboardType(.numberPad) TextField("Key", text: $key) TextField("Difficulty", text: $difficulty) TextField("Tempo (BPM)", value: $tempo, format: .number) .keyboardType(.numberPad) }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
337
Feb ’25
"Add-on" services no longer supported?
Our MacOS app has for some time been able to create so-called "add-on" services, which are dynamically written to individual bundles in ~/Library/Services/ (as opposed to being statically defined in the app's Info.plist). These worked fine for a long time until recently. They still appear in other app Services menus, but do not get as far as calling the specified instance method in our app. Does anyone know if add-on services are no longer supported? Perhaps due to some new security constraint? The documentation on app services in general seems to be out of date. I did try copying the add-on service definition from the add-on plist into the app's Info.plist. That seemed to work, so the basic specification doesn't seem to have changed.
Topic: UI Frameworks SubTopic: AppKit
0
0
272
Jan ’25
Widget archival failed due to image being too large
I'm trying to setup a widget to pull an image down from a webserver and I'm running into an error of Widget archival failed due to image being too large [9] - (1024, 1024), totalArea: 1048576 > max[718080.000000]. I've tried two different approaches to resolve this error and both have failed to resolve the image. I've also confirmed that I'm getting the image in the AppIntentTimelineProvider. private func getImageUI(urlString: String) -> UIImage? { guard let url = URL(string: urlString) else { return nil } guard let imageData = try? Data(contentsOf: url) else { return nil } return UIImage(data: imageData)?.resizedForWidget() } Is there another approach I could take on addressing this issue so the image appears on the widget? Simple approach extension UIImage { func resized(toWidth width: CGFloat, isOpaque: Bool = true) -> UIImage? { let canvas = CGSize(width: width, height: CGFloat(ceil(width/size.width * size.height))) let format = imageRendererFormat format.opaque = isOpaque return UIGraphicsImageRenderer(size: canvas, format: format).image { _ in draw(in: CGRect(origin: .zero, size: canvas)) } } } extension UIImage { /// Resize the image to strictly fit within WidgetKit’s max allowed pixel area (718,080 pixels) func resizedForWidget(maxArea: CGFloat = 718_080.0, isOpaque: Bool = true) -> UIImage? { let originalWidth = size.width let originalHeight = size.height let originalArea = originalWidth * originalHeight print("🔍 Original Image Size: \(originalWidth)x\(originalHeight) → Total Pixels: \(originalArea)") // ✅ If the image is already within the limit, return as is if originalArea <= maxArea { print("✅ Image is already within the allowed area.") return self } // 🔄 Calculate the exact scale factor to fit within maxArea let scaleFactor = sqrt(maxArea / originalArea) let newWidth = floor(originalWidth * scaleFactor) // Use `floor` to ensure area is always within limits let newHeight = floor(originalHeight * scaleFactor) let newSize = CGSize(width: newWidth, height: newHeight) print("🛠 Resizing Image: \(originalWidth)x\(originalHeight) → \(newWidth)x\(newHeight)") // ✅ Force bitmap rendering to ensure the resized image is properly stored let format = UIGraphicsImageRendererFormat() format.opaque = isOpaque format.scale = 1 // Ensures we are not letting UIKit auto-scale it back up let renderer = UIGraphicsImageRenderer(size: newSize, format: format) let resizedImage = renderer.image { _ in self.draw(in: CGRect(origin: .zero, size: newSize)) } print("✅ Final Resized Image Size: \(resizedImage.size), Total Pixels: \(resizedImage.size.width * resizedImage.size.height)") return resizedImage } } These are logs from a failed image render if that helps 🔍 Original Image Size: 720.0x1280.0 → Total Pixels: 921600.0 🛠 Resizing Image: 720.0x1280.0 → 635.0x1129.0 ✅ Final Resized Image Size: (635.0, 1129.0), Total Pixels: 716915.0
1
0
488
Feb ’25
Retrieve input field text as a keyboard extension in Swift
I am able to retrieve the text in the input field by doing: let contextBeforeInput = textDocumentProxy.documentContextBeforeInput ?? "" let contextAfterInput = textDocumentProxy.documentContextAfterInput ?? "" let fullText = contextBeforeInput + contextAfterInput However, when I'm pasting text into the input field, textDocumentProxy.documentContextBeforeInput refuses to return the entire text from the input field but instead only returns the last two sentences. I have tried this with the input fields in WhatsApp, Signal, and Telegram and it's all the same, so it doesn't seem to be caused by the specific app. At first I thought it was a limitation imposed by Apple but other third party keyboard extensions such as Grammarly are able to pick up the whole pasted text from the input field, so how are they doing it?
Topic: UI Frameworks SubTopic: UIKit
0
0
234
Jan ’25
Adding Markdown support in notes app
Hi guys, I’m making a simple note taking app and I want to support markdown functionality. I have tried to find libraries and many other GitHub repos but some of them are slow and some of them are very hard to implement and not very customizable. In WWDC 22 apple also made a markdown to html document app and I also looked at that code and it was awesome. It was fast and reliable (Apple btw). But the only problem I am facing is that the markdown text is on the left side and the output format is on the right in the form of html. I don’t want that I want both in the same line. In bear notes and things 3 you can write in markdown and you can see that it is converting in the same line. I have also attached example videos. So, I have markdown parser by apple but the only thing in the way is that it is converting it into a html document. Please help me with this. Also please look into the things 3 video they have also completely customized the text attributes selection menu. By default with UITextView we can only enable text attributes and it shows like this. By clicking more we get the complete formatting menu but not the slider menu which is more convenient. Please also help me this. I don’t know if I can provide apple file but it is from wwdc 22 supporting desktop class interaction
0
0
363
Feb ’25
Popover in full-screen apps doesn't keep menu bar open
I have an app that acts as an agent (no dock/app, just menu bar icon). When the icon is clicked, I show a popover with a small user interface. This works great, however, there is an issue. When a certain app is in full-screen and then my menu bar icon is clicked, the user interface shows just fine, until the mouse is moved outside the menu bar - then the user interface stays but the menu bar dismisses and closes. Is there a way to keep the menu bar open, like when clicking on Control Center, in full-screen apps? This is how I open my popover: if let button = statusItem.button { if popover.isShown { self.popover.performClose(sender) } else { popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY) popover.contentViewController?.view.window?.makeKey() } } }
2
0
225
Jan ’25
Numerous Undefined symbol errors
Getting these two warnings: Could not find or use auto-linked framework 'CoreAudioTypes': framework 'CoreAudioTypes' not found Could not parse or use implicit file '/Applications/Xcode16.0/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd': cannot link directly with 'SwiftUICore' because product being built is not an allowed client of it Followed by 100 + errors like below Undefined symbol: _TIFFCleanup & Undefined symbol: _TIFFReadRGBAImageOriented ..... Any ideas? I have tried adding CoreAudioTypes etc. Error is not clear. Am trying to stop using Rosetta
Topic: UI Frameworks SubTopic: General
2
0
781
Dec ’24
NavigationSplitView detail view not updating
I have a NavigationSplitView with all three columns, and NavigationLinks in the sidebar to present different Lists for the content column. When a list item is selected in the content view, I want to present a view in the detail view. Since different detail views should be presented for different content views, I represent state like this (some details omitted for space): // Which detail view to show in the third column enum DetailViewKind: Equatable { case blank case localEnv(RegistryEntry) case package(SearchResult) } // Which link in the sidebar was tapped enum SidebarMenuItem: Int, Hashable, CaseIterable { case home case localEnvs case remoteEnvs case packageSearch } // Binds to a DetailViewKind, defines the activate SidebarMenuItem struct SidebarView: View { @State private var selectedMenuItem: SidebarMenuItem? @Binding var selectedDetailView: DetailViewKind var body: some View { VStack(alignment: .leading, spacing: 32) { SidebarHeaderView() Divider() // Creates the navigationLinks with a SidebarMenuRowView as labels SidebarMenuView(selectedMenuItem: $selectedMenuItem, selectedDetailView: $selectedDetailView) Spacer() Divider() SidebarFooterView() } .padding() .frame(alignment: .leading) } } struct SidebarMenuRowView: View { var menuItem: SidebarMenuItem @Binding var selectedMenuItem: SidebarMenuItem? @Binding var selectedDetailView: DetailViewKind private var isSelected: Bool { return menuItem == selectedMenuItem } var body: some View { HStack { Image(systemName: menuItem.systemImageName).imageScale(.small) Text(menuItem.title) Spacer() } .padding(.leading) .frame(height: 24) .foregroundStyle(isSelected ? Color.primaryAccent : Color.primary) .background(isSelected ? Color.menuSelection : Color.clear) .clipShape(RoundedRectangle(cornerRadius: 10)) .navigationDestination(for: SidebarMenuItem.self) { item in navigationDestinationFor(menuItem: item, detailView: $selectedDetailView) } .onTapGesture { if menuItem != selectedMenuItem { selectedMenuItem = menuItem } } } } // Determines which detail view to present struct DetailView: View { @Binding var selectedDetailView: DetailViewKind var innerView: some View { switch selectedDetailView { case .blank: AnyView(Text("Make a selection") .font(.subheadline) .foregroundStyle(.secondary) .navigationSplitViewColumnWidth(min: 200, ideal: 350)) case .localEnv(let regEntry): AnyView(EnvironmentDetailView(regEntry: regEntry)) case .package(let searchResult): AnyView(PackageDetailView(searchResult: searchResult)) } } var body: some View { innerView } } struct ContentView: View { @State private var detailView: DetailViewKind = .blank var body: some View { NavigationSplitView { SidebarView(selectedDetailView: $detailView) .navigationSplitViewColumnWidth(175) } content: { HomeView() .navigationSplitViewColumnWidth(min: 300, ideal: 450) } detail: { DetailView(selectedDetailView: $detailView) } } } My issue is that the detail view is not updated when the ContentView's detailView property is updated. I've verified that the value itself is changing, but the view is not. I searched around to see why this would be (this is my first Swift/SwiftUI application) and from what I gather a @Binding alone will not cause a view to be updated, that binding either needs to be used in the view hierarchy, or it needs to be stored as a @State property that gets updated when the binding value changes. I added a dummy @State property to DetailView and that still doesn't work, so I'm a little confused: struct DetailView: View { @Binding var selectedDetailView: DetailViewKind @State private var dummyProp: DetailViewKind? var innerView: some View { switch selectedDetailView { case .blank: AnyView(Text("Make a selection") .font(.subheadline) .foregroundStyle(.secondary) .navigationSplitViewColumnWidth(min: 200, ideal: 350)) case .localEnv(let regEntry): AnyView(EnvironmentDetailView(regEntry: regEntry)) case .package(let searchResult): AnyView(PackageDetailView(searchResult: searchResult)) } } var body: some View { innerView.onChange(of: selectedDetailView) { dummyProp = selectedDetailView } } } Any ideas?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
443
Jan ’25
A glitch with retained view controllers on Catalyst
Hello! I discovered a bug on Catalyst about a three years ago but it still seems to be not fixed. My bug report number is FB9705748. The Internet is silent on this so I'm even not sure, perhaps it's only me. So to the problem. When you display UICollectionViewController or UIViewController that contains UICollectionView, interact with the collection view then dismiss the view controller, the displayed view controller isn't released if dismissal is done through navigation bar item. The problem occurs only when the run target is My Mac (Mac Catalyst). Everything is fine when you run on iOS or via My Mac (Designed for iPad). The sample project is uploaded to GitHub. It has a video that shows this strange behavior, see the log for 'deinit' messages. I did have some workaround to fix this but it stops to work, presumable on the new macOS. Also, chances are that it's not only UICollectionView which initiates the glitch, it's just that I only encounter it with collection views.
2
0
390
Feb ’25
Start tvOS SideBar Menu Collapsed
I'm trying to make the side bar menu on my tvOS app have the same behavior of Apple's tvOS App. I would like to have the side menu collapsed at the cold start of the app. I'm trying to achieve this by using the defaultFocus view modifier, which should make the button inside the TabView focused at the start of the app. But no matter what I do, the side bar always steels the focus from the inside button. struct ContentView: View { enum Tabs { case viewA case viewB } enum ScreenElements { case button case tab } @FocusState private var focusedElement: ScreenElements? @State private var selectedTab: Tabs? = nil var body: some View { Group { TabView(selection: $selectedTab) { Tab("View A", image: "square", value: .viewA) { Button("View A Button", action: {}) .frame(maxWidth: .infinity, alignment: .center) .focused($focusedElement, equals: .button) } } .tabViewStyle(.sidebarAdaptable) .focused($focusedElement, equals: .tab) } .defaultFocus($focusedElement, .button, priority: .userInitiated) } } Is there a way to start the side bar menu collapsed at the start up of the app?
0
0
387
Jan ’25
QLPreviewingController can access previewed file, but cannot load files referenced by the previewed file
I have an app on the Mac App Store (so sandboxed) that includes a QuickLook Preview Extension that targets Markdown files. It established a QLPreviewingController instance for the macOS QuickLook system to access and it works. I'm in the process of updating it so that it displays inline images referenced in the file as well as styling the file's text. However, despite setting Downloads folder read-only access permission (and user-selected, though I know that shouldn't be required: no open/save dialogs here) in the extension's entitlements, Sandbox refuses too allow access to the test image: I always get a deny(1) file-read-data error in the log. FWIW, the test file is referenced in the source Markdown as an absolute unix file path. I've tried different signings and no joy. I’ve tried placing the referenced image in various other locations. Also no joy. All I can display is the error-case bundle image for 'missing image'. Question is, is this simply something that QuickLook extensions cannot do from within the sandbox, or am I missing something? Is there anything extra I can do to debug this?
0
0
405
Jan ’25
UIColor labelColor in macOS made-for-iPad app is not solid black
When my iOS app runs on macOS in "designed for iPad" mode, the system foreground colour RGBA values seem strange. Looking at [UIColor labelColor], [UIColor secondaryLabelColor] etc. on iOS, I see values like these: (Light Mode) // R G B A fg0 = 0 0 0 255 fg1 = 10 10 13 153 fg2 = 10 10 13 76 fg3 = 10 10 13 45 Note in particular that fg0, aka labelColor, is solid black. When I run it on my Mac, the values I see are: // R G B A fg0 = 0 0 0 216 fg1 = 0 0 0 127 fg2 = 0 0 0 66 fg3 = 0 0 0 25 Here, fg0 has alpha = 216. The result is that it looks like a dark grey, on a white background. Of course it's reasonable for macOS to have a different colour palette than iOS - but native macOS apps seem to have solid 100% black as their foreground colour. Do others see this? What should I be doing? Note that I'm getting colour values using UIColor's getRed: blue: green: alpha: method and then using these colour values for some custom GPU drawing. Previously I was using solid black and white, but at some point I updated it to use UIColor in order to respond to light/dark-mode changes.
0
0
428
Dec ’24
Swift charts displaying wrong theme through UIHostingController
Hi there, I'm currently using UIHostingController to display swift charts in uikit. The problem im facing is that the UIHostingController isn't outputting the intended theme. When the simulator/phone is on dark mode the view is still in light mode. Iv'e tried to force the view to use dark mode with: .environment(\.colorScheme, .dark) But it doesn't seem to help. Here's how I implement the UIHostingController to my view: let controller = UIHostingController(rootView: StatVC()) controller.view.translatesAutoresizingMaksIntoConstraints = false addChild(controller) controller.didMove(toParent: self) view.addSubview(controller.view) where StatVC() is the swiftui view which contains the swift chart.
1
0
1.2k
Feb ’25
ishidden not working
I set the isHidden property of a view in traitCollectionDidChange and found that sometime it does not take effect after being set(value of isHidden actually not changed either). It looks like the setting does not take effect when triggered an even number of times, but it is normal when triggered an odd number of times. When setting isHidden, what actually goes into is [UIView (Rendering) setHidden:], which internally calls [UIView _ bitFlagValueAfterIncrementingHiddenManagement CountForKey: withIncrement: bitFlagValue:] to handle the relevant logic of "_UIViewPendingHiddenCount". Is this issue related to this part of the processing? returning 0 after calling seems normal This view is a UIStackView, and it is uncertain whether it is related to the type of view
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
370
Jan ’25
how to save the state when I open another APP ?
how to save the state of my APP when I open another APP so that It can restore when I re-open it? my app will use over 10mb memory so if I open another APP(my app will go background) it will closed at all. when I re-open it it will restart. but I do not want it I want if I open Page A and then it go background and when I re-open it it still is Page A and do not restart.
2
0
371
Feb ’25
https://forums.developer.apple.com/forums/post/question
Hi everyone, I’m working on an iOS app using both UITableViewDiffableDataSource and SwiftUI, and I’m facing two separate but puzzling issues: UITableViewDiffableDataSource Not Reusing Cells on first applying after initial Snapshot. After applying first time it is working as expected from second time. SwiftUI View’s inside UITableViewCell onDisappear Not Triggering the on first changes of snapshot after initial snapshot. With normal UITableView it is working fine. Issue causing - it is causing player &amp; cells to retain memory extensively Sample gist code for reproducing with diffable (DiffableTableViewExampleViewController) and working fine without diffable (RegularTableViewExampleViewController) https://gist.github.com/SURYAKANTSHARMA/d83fa9e7e0de309e27485100ba5aed17 Any insights or suggestions for these issues would be greatly appreciated! Thanks in advance!
0
0
224
Jan ’25
Reduce padding, spacing between list section header and search bar
Anyone know how to reduce the padding between list section header (plain style) and search bar? I have tried all available method on google but none work. The default list style does not have this big padding/space between the section header and the search bar. struct Demo: View { @State private var searchText: String = "" var body: some View { NavigationStack { List { Section { ForEach(0..<100) { index in Text("Sample value for \(index)") } } header: { Text("Header") .font(.headline) } } .listStyle(.plain) .navigationTitle("Demo") .navigationBarTitleDisplayMode(.inline) .searchable(text: $searchText) } } }
0
0
234
Feb ’25