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

WKWebView: Select Text and scroll beyond what's visible
Prime Objective I am trying to have a scroll view with a fixed header, a fixed footer, and a WKWebView in between. Using JavaScript, the height of the webView is determined and set to be large enough to hold the entire content. The Problem When selecting text on the webView, the view does not scroll when the edges are reached (this works if the webView is shown without being embedded in a Scroll view, or if it is the last element) What did I try? I tried reading the scroll view, or adding a gesture recognizer, but all of that does not work because the selection is essentially a system task Sourcecode Sourcecode to demonstrate the issue can be found on GitHub
1
0
352
Mar ’25
What happened to readable margins?
Am in the process of migrating some UIKit based apps over to SwiftUI, but for the life of me I cannot find the SwiftUI equivalent of Readable Content Margins. I have come across some workarounds that kind of, sort of work, but do not produce the same results when compared to running the same user interface written using UIKit on several sizes of iPads in portrait and landscape orientiations. is it something Apple has not gotten around to yet, because I realize SwiftUI is a work-in-progress, or do we not care about creating consistent readable margins in our apps anymore?
2
0
323
Mar ’25
SwiftUI textfield inside sheet produces extra padding when keyboard shown
I want to present a textfield inside a sheet. However when the keyboard is shown, the sheet view produces extra padding even though I explicitly set the frame of the textfield and the presentationDent to be the exact same height. Reproducible example: struct ContentView: View { @State var showSheet: Bool = false @State var text = "" var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") Button { showSheet.toggle() } label: { Text("Show Sheet") } } .sheet(isPresented: $showSheet) { TextField("Hello", text: $text) .frame(height: 44) .background(.red) .presentationDetents([.height(44)]) .presentationDragIndicator(.hidden) } } } Does anyone know how to resolve this issue?
1
0
484
Feb ’25
Document-based app failing in Mac Catalyst
A document-based app that's been running fine on iPad and Mac Catalyst has stopped working on the Mac as of Sequoia 15.3. After the user selects a document to open, my app never gets called back from Apple's framework. (The app works fine on iPadOS.) Anybody else see this? I filed a feedback, FB16506048, several weeks ago but have had no reply.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
190
Mar ’25
@State memory leak Xcode 16.2
Hi, A class initialized as the initial value of an @State property is not released until the whole View disappears. Every subsequent instance deinitializes properly. Am I missing something, or is this a known issue? struct ContentView: View { // 1 - init first SimpleClass instance @State var simpleClass: SimpleClass? = SimpleClass(name: "First") var body: some View { VStack { Text("Hello, world!") } .task { try? await Task.sleep(for: .seconds(2)) // 2 - init second SimpleClass instance and set as new @State // "First" should deinit simpleClass = SimpleClass(name: "Second") // 3 - "Second" deinit just fine simpleClass = nil } } } class SimpleClass { let name: String init(name: String) { print("init: \(name)") self.name = name } deinit { print("deinit: \(name)") } } output: init: First init: Second deinit: Second Thanks
0
0
287
Feb ’25
Updated to @Observable, now the total not updated on each keystroke
Hi I am developing an app for counting money. One view is for entering the intended destinations specified by a donor. Each destination has a row with a TextField that has an OnChange to keep it all numeric. The model that holds the data is a class called AllocationItems, which I recently changed from having the protocol ObservableObject to having the macro @Observable. It mostly works the same, except that before with each key stroke the total would be updated, but now with the macro it only gets updated when I exit the current TextField by clicking on another TextField How do I get it to update the total with each keystroke? The code that shows the total is this: Text(allocations.totalAllocated.fmtCurrency) where allocations is an instance of AllocationItems with this definition: var totalAllocated: NSDecimalNumber { items.reduce(.zero) { $0 + $1.amountValue } } I hope someone knows why this has changed and can suggest a simple fix.
2
0
292
Feb ’25
TextField .alignmentGuide in Form leading point varies?
I have a Form with a custom TextField which uses a custom Text(). When I use .alignmentGuide on the Text() it seems the origin reference point varies with the length of, but not by the length of, the TextField label String. This is a problem when in a Form. My workaround has been to not use a TextField label but enclose the each TextField in a LabeledContent and then I can set the width of the label and align off of that. How does Form cause TextField to set it's width and why if using .alignmentGuide on Text() does the TextField label length even matter?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
237
Feb ’25
Loading secondary Icon
I want to add the option to choose an alternative icon inside the app. Is there a way to load an icon asset from within the app? I downloaded Apple’s alternative icon sample, which is supposed to show a list of icons to choose from, but even in the sample, it did not work. So the current solution is to add every alternative icon along with another image asset of the same image to display to the user. This sounds like a waste of bytes. Thank you in advance for any help.
Topic: UI Frameworks SubTopic: General
0
0
76
Mar ’25
Why is UIViewController.dismissViewControllerAnimated marked as NS_SWIFT_DISABLE_ASYNC?
In the header for UIViewController, the method dismissViewControllerAnimated is declared like this: - (void)dismissViewControllerAnimated: (BOOL)flag completion: (void (^ __nullable)(void))completion NS_SWIFT_DISABLE_ASYNC API_AVAILABLE(ios(5.0)); NS_SWIFT_DISABLE_ASYNC means that there's no async version exposed like there would normally be of a method that exposes a completion handler. Why is this? And is it unwise / unsafe for me to make my own async version of it using a continuation? My use case is that I want a method that will sequentially dismiss all view controllers presented by a root view controller. So I could have this extension on UIViewController: extension UIViewController { func dismissAsync(animated: Bool) async { await withCheckedContinuation { continuation in self.dismiss(animated: animated) { continuation.resume() } } } func dismissPresentedViewControllers() async { while self.topPresentedViewController != self { await self.topPresentedViewController.dismissAsync(animated: true) } } var topPresentedViewController: UIViewController { var result = self while result.presentedViewController != nil { result = result.presentedViewController! } return result }
0
0
374
Feb ’25
Custom keypad touchUpInside events not working in iOS18
I have a custom keypad to accept numeric input for iPads that I have been using for many years now. This is longstanding working code. With iOS 18 the touchUpInside (and other) events in the underlying Objective-C modules are not called in the file owner module when activated from the interface. The buttons seem to be properly activated based on the visual cues (they change colors when pressed). This is occurring in both simulators and on hardware. Setting the target OS version does not help. What could the cause and/or solution of this be?
0
0
75
Mar ’25
Is it possible to automatically flip device orientation?
Hello togehter, i do have the following question. If I have my App run in landscape mode and a sheet view get's called, will it be possible to switch automatically from landscape mode in portrait mode and fix this device orientation? Once the sheet view get's dismissed or closed, the original view will come back and the device orientation shall switch back to landscape mode. Thanks you so much for your help!
0
0
248
Feb ’25
[NSRulerView] Is it buggy in Monterey?
I have a NSRulerView with a vertical orientation. It works fine from macOS 10.13 to 11.x. In macOS Monterey (12.2.1 here), the ruler view is not receiving drawHashMarksAndLabelsInRect: messages when the associated NSTextView is scrolled vertically. When the parent NSScrollView is resized, the ruler view is correctly refreshed on all macOS versions. [Q] Is it a known bug in macOS Monterey?
2
0
842
Mar ’25
An unresolvable crash.
My app is experiencing a recurring crash in the PRD environment, but it cannot be reproduced locally or in QA testing. Below is the crash log—I’d appreciate any help or insights on how to diagnose and resolve this issue. Thank you! 0 libobjc.A.dylib 0x2354 objc_release_x0 + 16 1 libobjc.A.dylib 0x2354 objc_release + 16 2 libobjc.A.dylib 0x4e38 AutoreleasePoolPage::releaseUntil(objc_object**) + 204 3 libobjc.A.dylib 0x4b8c objc_autoreleasePoolPop + 260 4 FrontBoardServices 0x1f4d0 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 176 5 FrontBoardServices 0x2eb90 -[FBSWorkspaceScenesClient _callOutQueue_sendDidCreateForScene:transitionContext:completion:] + 468 6 libdispatch.dylib 0x3fa8 _dispatch_client_callout + 20 7 libdispatch.dylib 0x79f0 _dispatch_block_invoke_direct + 284 8 FrontBoardServices 0x18378 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52 9 FrontBoardServices 0x182f8 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240 10 FrontBoardServices 0x181d0 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28 11 CoreFoundation 0x73f3c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 12 CoreFoundation 0x73ed0 __CFRunLoopDoSource0 + 176 13 CoreFoundation 0x76b94 __CFRunLoopDoSources0 + 344 14 CoreFoundation 0x75d2c __CFRunLoopRun + 840 15 CoreFoundation 0xc8274 CFRunLoopRunSpecific + 588 16 GraphicsServices 0x14c0 GSEventRunModal + 164 17 UIKitCore 0x3ee77c -[UIApplication _run] + 816 18 UIKitCore 0x14e64 UIApplicationMain + 340
Topic: UI Frameworks SubTopic: UIKit
2
0
313
Feb ’25
Animating Text foregroundStyle with gradients
Hello! We can animate Text color via foregroundStyle very nicely in SwiftUI like so: Text("Some text here") .foregroundStyle(boolValue ? Color.green : Color.blue) withAnimation { boolValue.toggle() } However, if the foregroundStyle is a gradient, the color of the Text view changes immediately without animation. The code below works to animate a gradient foregroundStyle on an SF Symbol, but it does not work when applied to a Text view. Is it possible to animate a Text view foregroundStyle between gradient values? Image(systemName: "pencil.circle.fill") .foregroundStyle(boolValue ? .linearGradient(colors: [.red, .orange], startPoint: .top, endPoint: .bottom) : .linearGradient(colors: [.green, .blue], startPoint: .top, endPoint: .bottom)) Thanks for your help!
1
0
334
Mar ’25
How do I properly mix SwiftUI Views with Auto Layout Constraint animations?
I have a SwiftUI View I've introduced to a UIKit app, using UIHostingController. The UIView instance that contains the SwiftUI view is animated using auto layout constraints. In this code block, when a view controller's viewDidAppear method I'm creating the hosting controller and adding its view as a subview of this view controller's view, in addition to doing the Container View Controller dance. override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) let hostingViewController = UIHostingController(rootView: TestView()) hostingViewController.view.translatesAutoresizingMaskIntoConstraints = false addChild(hostingViewController) view.addSubview(hostingViewController.view) let centerXConstraint = hostingViewController.view.centerXAnchor.constraint(equalTo: view.centerXAnchor) let topConstraint = hostingViewController.view.topAnchor.constraint(equalTo: view.topAnchor) widthConstraint = hostingViewController.view.widthAnchor.constraint(equalToConstant: 361) heightConstraint = hostingViewController.view.heightAnchor.constraint(equalToConstant: 342) NSLayoutConstraint.activate([centerXConstraint, topConstraint, widthConstraint, heightConstraint]) hostingViewController.didMove(toParent: self) self.hostingViewController = hostingViewController } I add a button to the UI which will scale the UIHostingViewController by adjusting its height and width constraints. When it's tapped, this action method runs. @IBAction func animate(_ sender: Any) { widthConstraint.constant = 120.3 heightConstraint.constant = 114.0 UIView.animate(withDuration: 0.5) { self.view.layoutIfNeeded() } } The problem is, the SwiftUI view's contents "jump" at the start of the animation to the final height, then animate into place. I see this both using UIView.animate the UIKit way, or creating a SwiftUI animation and calling `UIView. What else do I need to add to make this animate smoothly?
1
0
467
Feb ’25
How to make app for iPhone and iPad separatly
I released an app for iPhone (and it's could be downloaded for iPad also), and now I developered another app for iPad version with the same code and logic but I modified the layout to fit bigger screen and make better user experience and appearance. Howevert the app review rejected my release due to the duplicate content, how can I solve it?
Topic: UI Frameworks SubTopic: General
0
0
47
Mar ’25
Guidelines for ViewThatFits to avoid run-time crashes
TLDR: What rules ensure you won't have sporadic run-time crashes when using ViewThatFits? My app crashes - luckily reproducible. But the code appeared syntacticly and logically correct. Simplified excerpt: https://github.com/alanrick/Experiment3 The crash is caused by ViewThatFits being overwhelmed by concurrent changes in other views, exacerbated by animation effects. In the original code the problem was even worse because I'd gone overboard and used ViewThatFits in sub-views making the whole thing too dynamic. 

 My first rule is: Do not use nested ViewThatFits. 

 But this alone is not sufficient. What other rules can I apply to ensure I won't have hard-to-detect run-time crashes when using ViewThatFits?
Topic: UI Frameworks SubTopic: SwiftUI
2
0
444
Feb ’25
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.3k
Feb ’25
TextField using numberPad shows incorrectly shows autofill for one time code
If I show a textfield in my app and set nothing else on it but the following, The keyboard will show an autofill suggestion from a password manager for a one time code. textField.keyboardType = .numberPad In this case, the text field is for typing in a count, so iOS suggesting to autofill a one time code is incorrect. Setting textField.textContentType to nil has no affect on the behaviour. Prerequisites to reproduce an app with an associated domain an entry in a password manager with a one time code for the domain a textfield with keyboardType set to numberPad
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
670
Feb ’25
alternateIconName
I config of an alternate icon on the App Store Connect product page optimization. After the app launches, can I retrieve the name of this configured icon through UIApplication.shared.alternateIconName?
1
0
301
Mar ’25