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

` UIBezierPath(roundedRect:cornerRadius:)` renders Inconsistently at Specific Size-to-Radius Ratios
Hello everyone, I've encountered a fascinating and perplexing rendering anomaly when using UIBezierPath(roundedRect:cornerRadius:) to create a CGPath. Summary of the Issue: When the shortest side of the rectangle (min(width, height)) is just under a certain multiple of the cornerRadius (empirically, around 3x), the algorithm for generating the path seems to change entirely. This results in a path with visually different (and larger) corners than when the side is slightly longer, even with the same cornerRadius parameter. How to Reproduce: The issue is most clearly observed with a fixed cornerRadius while slightly adjusting the rectangle's height or width across a specific threshold. Create a UIView (contentView) and another UIView (shadowView) behind it. Set the shadowView.layer.shadowPath using UIBezierPath(roundedRect: contentView.bounds, cornerRadius: 16).cgPath. Adjust the height of the contentView. Observe the shadowPath at height 48 vs. height 49 Minimal Reproducible Example: Here is a simple UIViewController to demonstrate the issue. You can drop this into a project. Tapping the "Toggle Height" button will switch between the two states and print the resulting CGPath to the console. import UIKit class PathTestViewController: UIViewController { private let contentView = UIView() private let shadowView = UIView() private var heightConstraint: NSLayoutConstraint! private let cornerRadius: CGFloat = 16.0 private let normalHeight: CGFloat = 49 private let anomalyHeight: CGFloat = 48 override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemGray5 setupViews() setupButton() } override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() updateShadowPath() } private func updateShadowPath() { let newPath = UIBezierPath(roundedRect: contentView.bounds, cornerRadius: cornerRadius).cgPath shadowView.layer.shadowPath = newPath } private func setupViews() { // ContentView (the visible rect) contentView.backgroundColor = .systemBlue contentView.translatesAutoresizingMaskIntoConstraints = false contentView.isHidden = true // ShadowView (to render the path) shadowView.layer.shadowColor = UIColor.black.cgColor shadowView.layer.shadowOpacity = 1 shadowView.layer.shadowRadius = 2 shadowView.layer.shadowOffset = .zero shadowView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(shadowView) view.addSubview(contentView) heightConstraint = contentView.heightAnchor.constraint(equalToConstant: normalHeight) NSLayoutConstraint.activate([ contentView.centerXAnchor.constraint(equalTo: view.centerXAnchor), contentView.centerYAnchor.constraint(equalTo: view.centerYAnchor), contentView.widthAnchor.constraint(equalToConstant: 300), heightConstraint, shadowView.topAnchor.constraint(equalTo: contentView.topAnchor), shadowView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), shadowView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), shadowView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), ]) } private func setupButton() { let button = UIButton(type: .system, primaryAction: UIAction(title: "Toggle Height", handler: { [unowned self] _ in let newHeight = self.heightConstraint.constant == self.normalHeight ? self.anomalyHeight : self.normalHeight self.heightConstraint.constant = newHeight UIView.animate(withDuration: 0.3) { self.view.layoutIfNeeded() } })) button.translatesAutoresizingMaskIntoConstraints = false view.addSubview(button) NSLayoutConstraint.activate([ button.centerXAnchor.constraint(equalTo: view.centerXAnchor), button.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20) ]) } } Evidence: CGPath Analysis Note: The CGPath data below is from my initial observation. At that time, height 48.7 produced a path with straight edges. Now, this "correct" path is only produced at height 49.0 or greater. The inconsistency now occurs at 48.7.* The key difference lies in the raw CGPath data. Path for Height = 48.7 (Expected Behavior) The path is constructed with lineto commands for the straight edges between the curved corners. // Path for Height 48.7 Path 0x60000300a0a0: moveto (24.4586, 0) lineto (24.5414, 0) // <-- Straight line on top edge curveto (31.5841, 0) (35.1055, 0) (38.8961, 1.19858) ... Path for Height = 48.6 (Anomalous Behavior) The lineto commands for the short edges disappear. The path is composed of continuous curveto commands, as if the two corners have merged into a single, larger curve. This creates the visual discrepancy. // Path for Height 48.6 Path 0x600003028630: moveto (24.1667, 0) lineto (24.1667, 0) // <-- Zero-length line curveto (24.1667, 0) (24.1667, 0) (24.1667, 0) lineto (25.375, 1.44329e-15) curveto (34.8362, -2.77556e-16) (43.2871, 5.9174) (46.523, 14.808) // <-- First curve curveto (48.3333, 20.5334) (48.3333, 25.8521) (48.3333, 36.4896) // <-- Second curve, no straight line in between ... min.length == 48 min.length == 49 My Questions: Is this change in the path-generation algorithm at this specific size/radius threshold an intended behavior, or is it a bug? Is this behavior documented anywhere? The threshold doesn't seem to be a clean side/radius == 2.0, so it's hard to predict. Is there a recommended workaround to ensure consistent corner rendering across these small size thresholds? Any insight would be greatly appreciated. Thank you! Environment: Xcode: 16.4 iOS: 16.5.1(iPad), 18.4(iphone simulator)
2
0
23
7h
SwiftData .deny deleteRule not working
I tried to use the .deny deleteRule but it seems to have no effect. The toolbar button adds an item with a relationship to a category to the context. Swiping on the category deletes the category even though an item is referencing the category. There is also no error thrown when saving the context. It is as if the deleteRule was not there. For other deleteRules like .cascade, the provided sample code works as expected. import SwiftUI import SwiftData @Model class Category { var name: String @Relationship(deleteRule: .deny) var items: [Item] = [] init(name: String) { self.name = name } } @Model class Item { var name: String var category: Category? init(name: String, category: Category) { self.name = name self.category = category } } struct DenyDeleteRule: View { @Environment(\.modelContext) private var modelContext @Query private var categories: [Category] @Query private var items: [Item] var body: some View { List { Section("Items") { ForEach(items) { item in Text(item.name) } } Section("Categories") { ForEach(categories) { category in VStack(alignment: .leading) { Text(category.name).bold() ForEach(category.items) { item in Text("• \(item.name)") } } } .onDelete(perform: deleteCategory) } } .toolbar { Button("Add Sample") { let category = Category(name: "Sample") let item = Item(name: "Test Item", category: category) modelContext.insert(item) } } } func deleteCategory(at offsets: IndexSet) { for index in offsets { let category = categories[index] modelContext.delete(category) do { try modelContext.save() } catch { print(error) } } } } #Preview { NavigationStack { DenyDeleteRule() } .modelContainer(for: [Item.self, Category.self], inMemory: true) }
0
0
9
9h
unable to click when ZoomNavigationTransition finished
I am using ".navigationTransition(ZoomNavigationTransition.zoom(sourceID: xxx, in: xxx))" to zooms the appearing view from a source view . When the appearing view dismissed, I can only click other view after a delay . It seems that the transition is not finished immediately when the appearing view dismissed . After a delay, the transition finished, than I can click other view. struct ContentView: View { @State private var path: NavigationPath = NavigationPath() @Namespace private var namespace var body: some View { NavigationStack(path: $path) { VStack(spacing: 0) { ForEach(["aaa", "bbb"], id: \.self) { string in Text(string) .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2) .contentShape(Rectangle()) .onTapGesture { path.append(string) } .matchedTransitionSource(id: string, in: namespace) } } .navigationDestination(for: String.self, destination: { route in Text(route) .navigationTransition(ZoomNavigationTransition.zoom(sourceID: route, in: namespace)) }) } } } When using sheet on appearing view, It seems that the transition is finished immediately when the appearing view dismissed. extension String: Identifiable { public var id: String { return self } } struct ContentView: View { @State private var path: NavigationPath = NavigationPath() @Namespace private var namespace @State private var stringToSheet: String? var body: some View { NavigationStack(path: $path) { VStack(spacing: 0) { ForEach(["aaa", "bbb"], id: \.self) { string in Text(string) .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height / 2) .contentShape(Rectangle()) .onTapGesture { stringToSheet = string } .matchedTransitionSource(id: string, in: namespace) } } .sheet(item: $stringToSheet) { newValue in Text(newValue) .navigationTransition(ZoomNavigationTransition.zoom(sourceID: newValue, in: namespace)) } } } }
Topic: UI Frameworks SubTopic: SwiftUI
0
0
24
16h
Regarding the deadline for adopting the UIScene life cycle
https://developer.apple.com/forums/thread/788293 In the above thread, I received the following response: "When building with the SDK from the next major release after iOS 26, iPadOS 26, macOS 26 and visionOS 26, UIKit will assert that all apps have adopted UIScene life cycle. Apps that fail this assert will crash on launch." does this mean that there will be no app crashes caused by UIKit in iOS 26, but there is a possibility of app crashes when building with the SDK provided from iOS 27 onwards?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
58
17h
iOS 26 Beta – Unexpected Shadow/Glow Around Fullscreen Video Player in SwiftUI
Hello everyone, I'm developing a SwiftUI app that includes a fullscreen video player (AVPlayerViewController or AVPlayerLayer). I'm currently testing the app on an iPhone 16 Pro running iOS 26 Beta, as well as on the corresponding simulator. With iOS 26, during video playback, an unexpected black or white glow/halo appears around the video, depending on the system appearance (dark/light mode). However, this issue does not occur when testing on iOS 18 — neither on device nor simulator. Has anyone encountered this issue? Is there any known workaround or solution to remove this visual effect on iOS 26? I've attached screenshot below to illustrate the problem. Thank you in advance for your help!
0
0
23
19h
Where is the NSToolbarItem badge property in macOS Tahoe?
According the video "Build an AppKit app with the new design" (https://developer.apple.com/videos/play/wwdc2025/310/), it is now possible to add a badge on a NSToolbarItem object. However, in don't see a badge in the NSToolbar API. The code example in the video includes for example "NSItemBadge.count(4)", but the only Google result for this is the video mentioned above. Is this still work in progress or I'm overlooking something?
0
0
22
21h
Why does the menu in my toolbar on iOS 26 "fly" to the top of the screen?
I have a toolbar in SwiftUI where two of the buttons are Menus. When I tap on the button the menu animates out into the correct position and then it flys to the top of the screen. When I tap on the menu button I get this. Then within 1 second the menu flys to the top of the screen and looks like this. My toolbar code looks like this. .toolbar { ToolbarItemGroup(placement: .bottomBar) { Menu { Button { markMyLocation() } label: { Label("Mark My Location", systemImage: "location") } ... (MORE BUTTONS) } label: { Image(systemName: "plus") } .menuOrder(.fixed) Spacer() Menu { Button { shareWithWebLink() } label: { Label("Share Map", systemImage: "square.and.arrow.up") } ... (MORE BUTTONS) } label: { Image(systemName: "square.and.arrow.up") } .menuOrder(.fixed) Button { presentHikeView() } label: { Image(systemName: "figure.hiking") } Button { presentMapsView() } label: { Image(systemName: "map") } Spacer() Button { search() } label: { Image(systemName: "magnifyingglass") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
1
1
37
1d
.chartScrollableAxes(.horizontal) prevents chartYAxisLabel from being postioned top right, over Y axis
Adding .chartScrollableAxes(.horizontal) to a chart prevents chartYAxisLabel from being positioned top right, over Y axis. We want the label at top right, over the Y-axis, but with chartScrollableAxes it is always top right relative to the initial chartXVisibleDomain, which puts it in the middle of the chart if chartXVisibleDomain < full x domain. import SwiftUI import Charts struct ContentView: View { @State private var numbers = (0..<100) .map { _ in Double.random(in: 0...100) } @State var visibleDomain : Int = 50 var body: some View { Chart(Array(zip(numbers.indices, numbers)), id: \.1) { index, number in LineMark( x: .value("Index", index), y: .value("Number", number) ) } .chartScrollableAxes(.horizontal) .chartXVisibleDomain(length: visibleDomain) .chartScrollPosition(initialX: 70) .chartYAxisLabel(position: .topTrailing, alignment: .center) { /* We want the label at top right, over the Y-axis, but with chartScrollableAxes it is always top right relative to the initial chartXVisibleDomain, which puts it in the middle of the chart if chartXVisibleDomain < full x domain */ Text("units") .foregroundStyle(.red) .fontWeight(.bold) } .padding() } } #Preview { ContentView() }
1
0
17
1d
Hide title bar in Xcode preview (macOS)
I am trying to hide the titlebar for a macOS app and despite searching throughout the entire day, there's nothing that points to how I can achieve this. I did find this page in the documentation but I don't understand it. https://developer.apple.com/documentation/uikit/uititlebar/titlevisibility How do I remove the part where it says Xcode Previews? I have used the following on my WindowGroup that works perfectly when the app is being run but it doesn't do anything in the preview. .windowStyle(.hiddenTitleBar)
Topic: UI Frameworks SubTopic: SwiftUI
0
0
21
1d
SwiftUI buttons behind NSToolbarView are not clickable on macOS 26 beta
Overview Starting with macOS 26 beta 1, a new NSGlassContainerView is added inside NSToolbarView. This view intercepts mouse events, so any SwiftUI Button (or other interactive view) overlaid on the title‑bar / toolbar area no longer receives clicks. (The same code works fine on macOS 15 and earlier.) Filed as FB18201935 via Feedback Assistant. Reproduction (minimal project) macOS 15 or earlier → button is clickable macOS 26 beta → button cannot be clicked (no highlight, no action call) @main struct Test_macOS26App: App { init() { // Uncomment to work around the issue (see next section) // enableToolbarClickThrough() } var body: some Scene { WindowGroup { ContentView() } .windowStyle(.hiddenTitleBar) // ⭐️ hide the title bar } } struct ContentView: View { var body: some View { NavigationSplitView { List { Text("sidebar") } } detail: { HSplitView { listWithOverlay listWithOverlay } } } private var listWithOverlay: some View { List(0..<30) { Text("item: \($0)") } .overlay(alignment: .topTrailing) { // ⭐️ overlay in the toolbar area Button("test") { print("test") } .glassEffect() .ignoresSafeArea() } } } Investigation In Xcode View Hierarchy Debugger, a layer chain NSToolbarView > NSGlassContainerView sits in front of the button. -[NSView hitTest:] on NSGlassContainerView returns itself, so the event never reaches the SwiftUI layer. Swizzling hitTest: to return nil when the result is the view itself makes the click go through: func enableToolbarClickThrough() { guard let cls = NSClassFromString("NSGlassContainerView"), let m = class_getInstanceMethod(cls, #selector(NSView.hitTest(_:))) else { return } typealias Fn = @convention(c)(AnyObject, Selector, NSPoint) -> Unmanaged<NSView>? let origIMP = unsafeBitCast(method_getImplementation(m), to: Fn.self) let block: @convention(block)(AnyObject, NSPoint) -> NSView? = { obj, pt in guard let v = origIMP(obj, #selector(NSView.hitTest(_:)), pt)?.takeUnretainedValue() else { return nil } return v === (obj as AnyObject) ? nil : v // ★ make the container transparent } method_setImplementation(m, imp_implementationWithBlock(block)) } Questions / Call for Feedback Is this an intentional behavioral change? If so, what is the recommended public API or pattern for allowing clicks to reach views overlaid behind the toolbar? Any additional data points or confirmations are welcome—please reply if you can reproduce the issue or know of an official workaround. Thanks in advance!
0
0
73
1d
SwiftUI app crashes (EXC_BAD_ACCESS) when view hierarchy becomes too large.
Hey! Our team is experiencing some issue in a large SwiftUI application. When loading large views, the app crashes with a EXC_BAD_ACCESS signal. This signal can be reported by Xcode either on the @main attribute, inside a view hierarchy, or any order property that is accessed in the view hierarchy. After some investigation we found several possible workarounds: Splitting up the view into smaller subviews Wrapping parts of the view into an AnyView, which isn't ideal. However, this only temporarily solved the issue. As the app becomes bigger, we run into this problem more frequently. When trying to reproduce this issue in a clean Xcode project, I came up with the following: struct ContentView: View { var body: some View { Text("Hello") .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} .task {} } } When running this, the app immediately crashes on an iPhone 14 (YMMV on different (newer) devices). Of course such a view is not very likely to occur, but in total a view hierarchy could have this many view modifiers. Is there some limit we should we aware of? How can we circumvent this? Thanks!
0
0
29
1d
iOS Battery Percentage Granularity Issue
When developing an iOS app that monitors or transmits the battery percentage (using UIDevice.current.batteryLevel), often expect to get updates for every 1% change in battery. However, on iOS, the batteryLevel property only updates in steps of approximately 5%. For example, the value jumps from 1.0 (100%) to 0.95 (95%), then to 0.90 (90%), and so on. It does not report intermediate values like 0.99, 0.98, etc.
3
0
34
1d
SwiftUI window top left aligned on macOS 26 beta 1
We ran into a bug with our app Bezel (https://getbezel.app). When running on macOS Tahoe, windows would get partially clipped. This is because we have SwiftUI views that are larger than the window size, our SwiftUI views are supposed to be centered, which they are on macOS 13, 14, 15. But on macOS 26 (beta 1), the window contents are top-left aligned. This seems to be a bug, I have submitted FB18201269. This is my code: WindowGroup { ZStack { Color.green ZStack { Color.yellow Text("Hi") } .aspectRatio(1, contentMode: .fill) .border(.red) } } This first screenshot shows the old behavior on macOS 15: This second screenshot shows the new behavior on macOS 26 (beta 1) Can anyone confirm if this is indeed a bug, or if this an intended change in behavior?
1
0
23
1d
Detect when tab bar minimizes (.tabBarMinimizeBehavior)
Hi! I'm working on a iOS 26 SwiftUI prototype that adds an element to the content of a screen only when the tab bar is fully visible and not minimized (via .tabBarMinimizeBehavior). Is there any way to detect when a tab bar is minimized? My hope is that I can use a ternary operator to display something only when a boolean is true. Here's some code to illustrate my idea: struct ContentView: View { @State var isTabBarMinimized: Bool = false var body: some View { TabView { Tab("View1", systemImage: "rainbow") { // Only appears when tab bar is fully visible Color.blue .opacity(isTabBarMinimized? 0 : 1 ) } Tab("View2", systemImage: "rainbow") { View2() } Tab("View3", systemImage: "rainbow") { View3() } Tab("View4", systemImage: "rainbow") { View4() } } .tabBarMinimizeBehavior(.onScrollDown) } }
0
0
31
1d
Error querying optional Codable with SwiftData
I'm building a SwiftUI app using SwiftData. In my app I have a Customer model with an optional codable structure Contact. Below is a simplified version of my model: @Model class Customer { var name: String = "" var contact: Contact? init(name: String, contact: Contact? = nil) { self.name = name self.contact = contact } struct Contact: Codable, Equatable { var phone: String var email: String var allowSMS: Bool } } I'm trying to query all the Customers that have a contact with @Query. For example: @Query(filter: #Predicate<Customer> { customer in customer.contact != nil }) var customers: [Customer] However no matter how I set the predicate I always get an error: BugDemo crashed due to an uncaught exception NSInvalidArgumentException. Reason: keypath contact not found in entity Customer. How can I fix this so that I'm able to filter by contact not nil in my Model?
0
0
41
1d
How to do full width .sheet() on iOS 26+ with small presentation detents?
For certain contexts, I'd like to still have my .sheet() be full width even when it's at a small height. In iOS 26, the sheet is inset from the edges at small detents and expands to full width at larger detents. For example, I have a view where I have a .sheet() that has a height of about 200pts and it contains a horizontally scrolling picker that extends past the bounds of the screen. I'd like the .sheet to expand all the way to the edge when at these small detents, like it would previous to iOS 26. Is it possible to configure this? This change will break a number of existing designs :( A new ViewModifier such as enum PresentationWidth { case dynamic, fixed } func presentationWidth(_ width: PresentationWidth) -> some View would be very nice.
0
0
32
1d
Update Widget Every Minute
Is this not possible? I have a simple text view that shows the time, but it doesn't stay in sync with the time. I've tried to use a timer like I do inside the app, but that didn't work. I tried TimelineView with it set to every minute, and that didn't work. I tried to use the dynamic date using Text(date, style: ) and that didn't work. I looked it up and apparently it's a limitation to WidgetKit, however, I don't understand how the Apple Clock widget can have a moving second hand that updates properly. Do I just need to add a bunch of entries in the TimelineProvider? Right now, it's just the default that gets loaded when you create a Widget extension. func timeline(for configuration: SingleClockIntent, in context: Context) async -> Timeline<SingleClockEntry> { var entries: [SingleClockEntry] = [] // Generate a timeline consisting of five entries an hour apart, starting from the current date. let currentDate = Date() for hourOffset in 0 ..< 5 { let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! let entry = SingleClockEntry(date: entryDate, configuration: configuration) entries.append(entry) } return Timeline(entries: entries, policy: .atEnd) } EDIT: This code below seems to be working. Can someone confirm if it will continue to work, or will it eventually stop updating? func timeline(for configuration: SingleClockIntent, in context: Context) async -> Timeline<SingleClockEntry> { var entries: [SingleClockEntry] = [] let calendar = Calendar.current let current = Date() // Get the next minute let secondEntryDate = calendar.nextDate(after: current, matching: DateComponents(second: 0), matchingPolicy: .strict, direction: .forward)! entries.append(SingleClockEntry(date: current, configuration: configuration)) // Adds current time entries.append(SingleClockEntry(date: secondEntryDate, configuration: configuration)) // Adds next minute after current time // Add an entry every min for the next 30 minutes for offset in 0..<30 { let entryDate = Calendar.current.date(byAdding: .minute, value: offset, to: secondEntryDate)! let entry = SingleClockEntry(date: entryDate, configuration: configuration) entries.append(entry) } return Timeline(entries: entries, policy: .atEnd) }
3
0
53
1d