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

Control Widget SF image cannot stably display
I'm working on the control widget which should display the SF image on the UI, but I have found that it cannot be displayed stably. I have three ExampleControlWidget which is about the type egA egB and egC, it should all be showed but now they only show the text and placeholder. I'm aware of the images should be SF image and I can see them to show perfectly sometimes, but in other time it is just failed. This's really confused me, can anyone help me out? public enum ControlWidgetType: Sendable { case egA case egB case egC public var imageName: String { switch self { case .egA: return "egA" case .egB: return "egB" case .egC: return "egC" } } } struct ExampleControlWidget: ControlWidget { var body: some ControlWidgetConfiguration { AppIntentControlConfiguration( kind: kind, provider: Provider() ) { example in ControlWidgetToggle( example.name, isOn: example.state.isOn, action: ExampleControlWidgetIntent(id: example.id), valueLabel: { isOn in ExampleControlWidgetView( statusText: isOn ? Localization.on.text : Localization.off.text, bundle: bundle, widgetType: .egA //or .egB .egC ) .symbolEffect(.pulse) } ) .disabled(example.state.isDisabled) } .promptsForUserConfiguration() } } public struct ExampleControlWidgetView: View { private let statusText: String private let bundle: Bundle private var widgetType: ControlWidgetType = .egA public init(statusText: String, bundle: Bundle, widgetType: ControlWidgetType) { self.statusText = statusText self.bundle = bundle self.widgetType = widgetType } public var body: some View { Label( statusText, image: .init( name: widgetType.imageName, // the SF Symbol image id bundled in the Widget extension bundle: bundle ) ) } } This is the normal display: These are the display that do not show properly: The results has no rules at all, I have tried to completely uninstall the APP and reinstall but the result is same.
3
0
354
3w
iOS18 Control Widget custom symbol preview failed
i export apple SF as custom sf for test. code is simple: var body: some ControlWidgetConfiguration { StaticControlConfiguration( kind:"ControlWidgetConfiguration" ) { ControlWidgetButton(action: DynamicWidgetIntent()) { Text("test") Image("custom_like") } }.displayName("test") } as we can see, it can't show image in the preview. but it can show image in the Control widget center. am i do some thing wrong?
5
7
1k
3w
How to correctly move a TextField selection cursor when inserting UTF16 text
I'm trying to implement a feature whereby a user can tap a button to insert a character at the cursor in a TextField - the cursor then needs to be moved forward to be in front of the insert character. I'm having trouble with characters such as π which are UTF16 encoded. In the following sample app, enter the following sequence: Enter 9 by keyboard tap + Enter 9 by keyboard tap π Enter 9 via keyboard tap + he TextField will show '9+9π+9' (i.e. the final + is inserted before 9 rather than after it. Any insight into what I am doing wrong? import SwiftUI @main struct TextInsertApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var text: String = "" @State private var selection: TextSelection? = nil var body: some View { TextField("", text: $text, selection: $selection) .background(.gray.opacity(0.4)) Button("+") { insert("+") } Button("π") { insert("π") } } func insert(_ insertString: String) { if let selection { if case let .selection(range) = selection.indices { if selection.isInsertion { text.insert(contentsOf: insertString, at: range.lowerBound) } else { text.replaceSubrange(range, with: insertString) } let cursor = text.utf16.index(range.upperBound, offsetBy: insertString.count) self.selection = .init(insertionPoint: cursor) } } else { text += insertString selection = .init(range: text.utf16.endIndex..<text.utf16.endIndex) } } }
1
0
164
4w
Text with Liquid Glass effect
I'm looking for a way to implement Liquid Glass effect in a Text, and I have issues. If I want to do gradient effect in a Text, no problem, like below. Text("Liquid Glass") .font(Font.system(size: 30, weight: .bold)) .multilineTextAlignment(.center) .foregroundStyle( LinearGradient( colors: [.blue, .mint, .green], startPoint: .leading, endPoint: .trailing ) ) But I cannot make sure that I can apply the .glassEffect with .mask or .foregroundStyle. The Glass type and Shape type argument looks like not compatible with the Text shape itself. Any solution to do this effect on Text ? Thanks in advance for your answers.
2
0
372
4w
Too many bugs porting to iOS 26
Has anyone noticed that there are way too many bugs caused by the liquid glass issues? I'm noticing apple adding private layer classes between existing UI views to add glassy effect and no way to disable them. Some of these bugs have no way around without rewriting the code from. For example, search controller doesn't work anymore on iOS 26 but does work on iOS 18. The tab bar controller doesn't show at all on iOS 26 but does on iOS 18. I'm wondering if other people are facing the same issues.
Topic: UI Frameworks SubTopic: General
0
0
356
4w
BUG: Toolbar Rendering Bug -- ToolbarItem Duplication when Back Button Hidden
To whom it may concern that deals with bugs in SwiftUI for iOS 26: Inadvertently discovered a bug which duplicates ToolbarItem in any placement in the toolbar when navigationBarBackButtonHidden is set to true. .toolbar{ ToolbarItem(placement: .confirmationAction) { Button("Stop", systemImage: "stop.fill"){ //some action } } } .navigationBarBackButtonHidden(true) Expected Behavior Show the ToolbarItem Actual Behavior Duplicates items in the placement position. Thank you.
1
0
145
4w
NSPathControl -setURL: crash on macOS Tahoe
I received the following crash: Thread 0 Crashed: libsystem_kernel.dylib __pthread_kill + 8 libsystem_pthread.dylib pthread_kill + 296 (pthread.c:1721) libsystem_c.dylib abort + 124 (abort.c:122) libc++abi.dylib __abort_message + 132 (abort_message.cpp:66) libc++abi.dylib demangling_terminate_handler() + 304 (cxa_default_handlers.cpp:76) libobjc.A.dylib _objc_terminate() + 156 (objc-exception.mm:496) libc++abi.dylib std::__terminate(void (*)()) + 16 (cxa_handlers.cpp:59) libc++abi.dylib __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 88 (cxa_exception.cpp:152) libc++abi.dylib __cxa_throw + 92 (cxa_exception.cpp:299) libobjc.A.dylib objc_exception_throw + 448 (objc-exception.mm:385) Foundation -[NSConcreteMutableAttributedString initWithString:] + 268 (NSAttributedString.m:1049) CloudDocs -[BRCloudPathComponentDisplayMetadata initWithDisplayName:suffix:url:icon:] + 180 (BRCloudPathComponentDisplayMetadata.m:75) CloudDocs -[NSURL(BRCloudPathComponent) br_pathComponentDisplayMetadataWithOptions:]_block_invoke + 516 (BRCloudPathComponentDisplayMetadata.m:292) CloudDocs -[NSArray(BRAdditions) br_transform:keepNull:] + 228 (NSArray+BRAdditions.m:20) CloudDocs -[NSURL(BRCloudPathComponent) br_pathComponentDisplayMetadataWithOptions:] + 76 (BRCloudPathComponentDisplayMetadata.m:276) AppKit -[NSPathCell _autoUpdateCellContents] + 2080 (NSPathCell.m:442) AppKit -[NSPathCell setURL:] + 76 (NSPathCell.m:599) AppKit -[NSPathControl setURL:] + 64 (NSPathControl.m:366) I tried reproducing on my end by passing various URLs in iCloud Drive to an NSPathControl, file reference urls, attempting to evict a URL from iCloud Drive then settings the URL property without luck. Setting the URL to nil does not crash (the property is nullable). I have no idea how to trigger that code path. Anyone else run into this and have a workaround?
2
0
55
4w
help() view modifier
I have a bunch of Buttons with a .help(Text("Help text")) modifier, inside of a VStack which has its own .help() modifier describing the entire section. The VStack help shows up only when I hover over the buttons, and the Button help never shows at all. If I comment out the VStack help, the individual button helps show. How do I get both to show up properly? I want the VStack to show if I am in the roundedBorder, unless I am over a Button with its own .help modifier. import SwiftUI struct BugReport: View { @State private var testp1 = false @State private var testp2 = false var body: some View { VStack { Text("Hello, World!") Button("Test1") { testp1.toggle() } .help("Change the test1") Button("Test2") { testp2.toggle() } .help("Change the test2") } .help("Testing stuff") .roundedBorder(color: .black) } } #Preview { BugReport() }
Topic: UI Frameworks SubTopic: SwiftUI
4
0
353
4w
CGContextDrawShading broken on MacOS Tahoe for apps built with MacOS SDK older than 14.5
On MacOS Tahoe (26.0 26.1 or 26.2), when loading an application that was built with an SDK older than version SDK 14.5, all CGContextDrawShading calls to draw onto the screen (inside of NSView drawRect:) fail silently, filling the path with a single color instead of a gradient. If rendering into a local CGBitmapContext instead of the NSView context on Tahoe, CGShading works as expected. On MacOS 15 and earlier, CGShading works as expected too. If the app is built with SDK version 14.5 or newer, CGShading works normally on MacOS Tahoe. For recent applications, they can of course be rebuilt with a more recent version of the SDK, which fixes the problem. However for Audio Units or any other type of plug-in, even if they are built with the "appropriate" SDK, if they are loaded inside of a legacy application that was built with an older SDK, the problem arises, which customers complain about and do not understand. I have noticed that there had been a few changes in MacOS Tahoe regarding the CGShading APIs, could this problem be related? If this issue cannot be fixed in an upcoming MacOS update, is there maybe a "defaults" value that can be changed? (since this behaviour is specific to a sdk version, I guess that it is triggered by a version check in the Frameworks and that there is a "defaults" value that can be changed to avoid this specific behaviour, as it is usually the case via a DefaultValueFunction)? I have already opened a feedback regarding this issue, but maybe someone already has a solution for this problem?
Topic: UI Frameworks SubTopic: AppKit
1
1
114
4w
SwiftUI using Mac Catalyst destination the destination but provided destination is iPhone 17 Pro
Using SwiftIUI with CommandGroup for iPad app on Xcode Version 26.2 (17C52). I tried to test on Mac Catalyst. Output view is iPad size but my SwiftUI view is small on the left. I tried to override the frame size used but none of the suggested ways compiled. Used both "Scaled for iPad" and "Optimized for Mac" in deployment Info with same results.
1
0
65
4w
AppIntents
Overview I have a custom type Statistics that has 3 properties inside it I am trying to return this as part of the AppIntent's perforrm method struct Statistics { var countA: Int var countB: Int var countC: Int } I would like to implement the AppIntent to return Statistics as follows: func perform() async throws -> some IntentResult & ReturnsValue<Statistics> { ... ... } Problem It doesn't make much sense to make Statistics as an AppEntity as this is only computed as a result. Statistics doesn't exist as a persisted entity in the app. Questions How can I implement Statistics? Does it have to be AppEntity (I am trying to avoid this)? (defaultQuery would never be used.) What is the correct way tackle this?
2
0
229
4w
Alternative Methods to Display App Icon in Core Spotlight Search Results Besides CFBundleDocumentTypes
I'm developing an iOS app that handles custom file types (e.g., .k files), and I want to ensure my app's icon appears in Core Spotlight search results, similar to how 两步路户外助手's icon shows up for associated files (as shown in the attached screenshot from iOS search). I know one standard way is to configure CFBundleDocumentTypes in the Info.plist to declare supported document types, which allows the system to associate files with my app and display the icon in search. However, I'm looking for alternative approaches or additional configurations that could achieve this without relying solely on CFBundleDocumentTypes, or perhaps in combination with it for better integration. For context: This is for iOS 26+ (or latest versions). The goal is to have the app icon visible directly in Spotlight/Core Spotlight results when searching for files or content indexed by my app. I've tried basic NSUserActivity and CSSearchableItem indexing, but the icon doesn't always appear as expected for file associations. Has anyone implemented this through other means, like exported UTIs, Launch Services, or custom searchable attributes? Any code snippets, documentation links, or best practices would be appreciated! (Attach your Figure 2 screenshot here to illustrate the desired behavior, e.g., the .k file with the app icon in search results.)
1
0
167
4w
[UIKit Glass Effect] - Opacity change from 0 to 1 does not work
When a UIVisualEffect with glass effect view is added with opacity 0, it remains hidden as expected. But when changing it back to 1 should make it visible, but currently it stays hidden forever. The bug is only reproducible on iOS 26.1 and iOS 26.2. It does not happen on iOS 26.0. The issue is also not reproducible with UIBlurEffect. Only happens for Glass effect Here is the repro link
3
0
340
4w
Modify the default gradient background of toolbar in iOS26
In the new iOS 26 design, the navigation bar and tab bar will have a dark gradient background. We found that the color of this gradient depends on the background color of the page. For example, in the following page, our background color is green, so the navigation bar and tab bar will change the gradient to green. Is there any way to change this gradient color? I tried .toolbarBackground(.hidden, for: .navigationBar), but does not work。 I tried .toolbarBackground(LinearGradient(colors: [.black.opacity(0.4), .black.opacity(0)], startPoint: .top, endPoint: .bottom), for: .navigationBar), but it looks like the default gradient is the superposition of the gradient I defined, not a replacement.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
123
4w
Using @Environment with TabView
Let me ask the general question first, then explain the context... Each Tab of a TabView defines a separate View hierarchy. (I'm assuming that the root view of each Tab defines its own NavigationStack.) Since an @Environment is supposed to serve data to the child views in its view hierarchy, does this mean that it is possible to define Environments in each tab's root view with the same name (i.e. key) but different values? (I.e., I want a subview to access an environment value for the current view hierarchy without requiring that the subview have any knowledge of which hierarchy it is being called from.) The actual use case has to do with using @Environment in a tabbed application to inject a router in subviews. (Each Tab has its own NavigationStack and its own NavigationPath.) I have an @Observable router class which manages a NavigationPath.. The root view of each Tab in the application has its own instance of that router object (and hence, it's own NavigationPath). I want to inject that router into all of the subviews in each Tab's view hierarchy, so that I can use path-based navigation. My current implementation injects the router throughout the view hierarchies via constructor injection. This works, but is a real pain and includes a bunch of duplicate code. I would like to use @Environment injection instead, but this can only work if @Environment stores its EnvironmentValues on a per view-hierarchy (rather than a per-application) basis. So, can this approach work? what experience can you share concerting router-based navigation in a TabView-based app? Thanks.
2
0
174
4w
Sheet keeps dismissing as soon as text focus
Anytime I launch a view that contains a textfield, as soon as it’s in focus the view dismisses, and I log this warning, I have tried everything I could think of and still no solution, anyone know a workaround to this? note: this happens both on simulator and physical devices -[rtiinputsystemclient remotetextinputsessionwithid:performinputoperation:] perform input operation requires a valid sessionid. input modality = keyboard, input operation = , custom infotype = uiemojisearchoperations
1
0
100
4w