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

brightnessDidChangeNotification does not seem to work on Mac Catalyst 15.5
Hi, I have been trying to subscribe to brightnessDidChangeNotification (https://developer.apple.com/documentation/uikit/uiscreen/brightnessdidchangenotification) with my code: var publisher = NotificationCenter.default.publisher(for: UIScreen.brightnessDidChangeNotification) .map { _ -> Double in return UIScreen.main.brightness } But it does seem that no such event is fired on Mac Catalyst 15.5. https://developer.apple.com/documentation/uikit/uiscreen/brightnessdidchangenotification claims that API is available since 13.1. Could anybody tell me if I'm doing something wrong or if the API is not supported at the moment? Thank you!
0
1
155
May ’25
SwiftUI Tabview - how to "kill" the views we do not use
I have the MainView as the active view if the user is logged in(authenticated). the memory allocations when we run profile is pretty good. We have graphql fetching, we have token handling eg: This is All heap: 1 All Heap & Anonymous VM 13,90 MiB 65408 308557 99,10 MiB 373965 Ratio: %0.14, %0.86 After what i have checked this is pretty good for initialise and using multiple repositories eg. But when we change tabs: 1 All Heap & Anonymous VM 24,60 MiB 124651 543832 156,17 MiB 668483 Ratio: %0.07, %0.40 And that is not pretty good. So i guess we need to "kill" it or something. How? I have tried some techniques in a forum this was a recommended way: public struct LazyView<Content: View>: View { private let build: () -> Content @State private var isVisible = false public init(_ build: @escaping () -> Content) { self.build = build } public var body: some View { build() Group { if isVisible { build() } else { Color.clear } } .onAppear { isVisible = true } .onDisappear { isVisible = false } } } But this did not help at all. So under here is the one i use now. So pleace guide me for making this work. import DIKit import CoreKit import PresentationKit import DomainKit public struct MainView: View { @Injected((any MainViewModelProtocol).self) private var viewModel private var selectedTabBinding: Binding<MainTab> { Binding( get: { viewModel.selectedTab }, set: { viewModel.selectTab($0) } ) } public init() { // No additional setup needed } public var body: some View { NavigationStack(path: Binding( get: { viewModel.navigationPath }, set: { _ in } )) { TabView(selection: selectedTabBinding) { LazyView { FeedTabView() } .tabItem { Label("Feed", systemImage: "house") } .tag(MainTab.feed) LazyView { ChatTabView() } .tabItem { Label("Chat", systemImage: "message") } .tag(MainTab.chat) LazyView { JobsTabView() } .tabItem { Label("Jobs", systemImage: "briefcase") } .tag(MainTab.jobs) LazyView { ProfileTabView() } .tabItem { Label("Profile", systemImage: "person") } .tag(MainTab.profile) } .accentColor(.primary) .navigationDestination(for: MainNavigationDestination.self) { destination in switch destination { case .profile(let userId): Text("Profile for \(userId)") case .settings: Text("Settings") case .jobDetails(let id): Text("Job details for \(id)") case .chatThread(let id): Text("Chat thread \(id)") } } } } } import SwiftUI public struct LazyView<Content: View>: View { private let build: () -> Content public init(_ build: @escaping () -> Content) { self.build = build } public var body: some View { build() } }
0
0
211
Mar ’25
Use Custom UIApplication Subclass with SwiftUI
I have a SwiftUI app which needs the Ivanti AppConnect SDK. The docs only show how to integrate it into a Swift/UIKit app. But I need it to work with SwiftUI. I probably could make a UIKit base app and then load my existing SwiftUI views and code through a SwiftUI component host or something. But I'd like to avoid that if possible. Here is where I'm stuck: The AppConnect framework loads through a custom UIApplication subclass in the main.swift file: import Foundation import AppConnect UIApplicationMain( CommandLine.argc, CommandLine.unsafeArgv, ACUIApplicationClassName, NSStringFromClass(AppDelegate.self) ) The startup works as expected, and the expected function is called in the AppDelegate class: func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {...} However, the SwiftUI view is not loaded and the scree stays blank. I implemented a SceneDelegate.swift class which doesn't seem to be called. Also, the following function in the AppDelegate doesn't get called either: func application( _ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {...} So how do I bootstrap SwiftUI with a custom UIApplication class? can that be done with the @main macro somehow? I'm still pretty new to Swift and iOS development. Any help is appreciated
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
0
69
May ’25
Bundling OSX installer plugin with productbuild/pkgbuild
I'm trying to create a .pkg installer with productbuild/pkgbuild. But I'd also like to add my custom installer plugin to this. I'm using the following script. I'd like to add my bundle into this script. Since there are no official docs from apple how to do this nor there are a lot of updated resources, here are some things I have tried. adding the following line to Distrubtion.xml <bundle id="pluginid" path="path/to/myplugin.bundle"/> adding component tag to pkgbuild also doesn't do anything --component "path/to/myplugin.bundle" The bundle itself is build with XCode - it is a simple UI for user to type some input in Apple provides documentation for Distribution.xml file, which supports different UI elements but doesn't support text input - docs I have been also looking at this tutorial , it is very outdated but i could still fit it to my needs except the part where the .bundle file needs to be inserted into .pkg. Note - there is no option to view the contents of .pkg file build with pkbuild/productbuild How can i do this process correctly? I would like to link my installer pane plugin to a generic .pkg(with licenses and so on). I'd appreciate any kind of help!
0
0
114
May ’25
CPTabBarTemplate in CarPlay Simulator: Tab Becomes Inactive on Re-selection
I am facing an issue in my CarPlay app using CPTabBarTemplate. The app has two tabs, and on launch, the first tab is correctly selected. However, when I tap on the first tab again, instead of staying active, it becomes inactive. This behavior is unexpected, as re-selecting the active tab should typically maintain its selected state. Has anyone else encountered this issue or found a workaround to prevent the tab from becoming inactive?
0
0
58
May ’25
Why is the pitch slider visible in SwiftUI tvOS map view?
Why is the pitch slider always visible in the SwiftUI tvOS map view? It doesn't even appear to be supported there, let alone the fact that I specify mapControlVisibility(.hidden). Am I missing something or is Apple? See attached screenshot. This really messes up my UI. Here is my code: import SwiftUI import MapKit struct ContentView: View { @State var position = MapCameraPosition.region(MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))) var body: some View { Map(position: $position) .mapControlVisibility(.hidden) .mapStyle(.standard(pointsOfInterest: .including(.airport))) } }
0
0
281
Mar ’25
Scroll offset incorrectly resets when animating insertion of ScrollView using .geometryGroup()
Hey, I've been having a problem with scroll views in combination with the .geometryGroup() modifier. I have filed a Feedback (FB17698293) but I also wanted to post this here in case someone maybe has a better workaround for the problem. Problem Whenever you conditionally insert a ScrollView inside a VStack that is modified with a .geometryGroup() modifier, the scroll view content offset resets itself after the insertion animation is done, even if you started scrolling inside the scroll view during the animation and haven't let go of the screen. This happens consistently and is fully reproducible (see below), both using a simulator and a real device. Unfortunately, this is a very annoying glitch that ruins a lot of cool UX components that rely on .geometryGroup(). The weird thing is that the glitch entirely disappears, if you add a simple, non-zero (but greater than 1) .padding() modifier to the VStack (.padding().geometryGroup()). I have no idea why this fixes the glitch, but it does. However, adding a padding is not feasible in many situations, so this workaround is not ideal. Steps to reproduce Launch the code below (using a simulator or a real device) and tap "Toggle Expansion" to insert the scroll view. As the view is animating in, drag the scroll content and hold it scrolled away from the top. Wait for the animation to complete. The scroll view will reset the content offset, even though the drag gesture is still active (i.e. you haven't lifted your finger to release the scroll view) On a real device, this sometimes even leads to an even worse visual artifact where the scroll view is rendered twice for a few frames; once with the correct offset, and once with the reset offset. I wanted to include a link to a gif/video showing the glitch, but it tells me that imgur is not allowed on the forums. Expected Behavior I want the scroll view to respect the content offset, even if I started changing it mid-animation. Xcode Version I am using Xcode 16.4 (16F6) but this problem has been occurring since the .geometryGroup() modifier has been release. I was only now able to pinpoint this problem exactly, so I'm filing this feedback. Code The entire code that reproduces the problem: import SwiftUI struct ContentView: View { @State private var isExpanded: Bool = false var body: some View { VStack { if isExpanded { ScrollView { Text(loremIpsum) } } Button("Toggle Expansion") { isExpanded.toggle() } } // .padding(10) // Adding a non-zero padding makes the glitch disappear .frame(maxWidth: .infinity) .geometryGroup() .animation(.default, value: isExpanded) } } #Preview { ContentView().preferredColorScheme(.dark) } // MARK: - Mock Data let loremIpsum = """ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt \ ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco \ laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \ pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt \ mollit anim id est laborum. """
Topic: UI Frameworks SubTopic: SwiftUI
0
0
129
May ’25
iOS UILabel textAlignment .justified results in wrong rect by layoutManager.boundingRect
I have a UILabel subclass showing NSAttributedString in which I need to draw a rounded rectangle background color around links: import UIKit class MyLabel: UILabel { private var linkRects = [[CGRect]]() private let layoutManager = NSLayoutManager() private let textContainer = NSTextContainer(size: .zero) private let textStorage = NSTextStorage() override func draw(_ rect: CGRect) { let path = UIBezierPath() linkRects.forEach { rects in rects.forEach { linkPieceRect in path.append(UIBezierPath(roundedRect: linkPieceRect, cornerRadius: 2)) } } UIColor.systemGreen.withAlphaComponent(0.4).setFill() path.fill() super.draw(rect) } override init(frame: CGRect) { super.init(frame: frame) setup() } required init?(coder: NSCoder) { super.init(coder: coder) setup() } private func setup() { numberOfLines = 0 adjustsFontForContentSizeCategory = true isUserInteractionEnabled = true lineBreakMode = .byWordWrapping contentMode = .redraw clearsContextBeforeDrawing = true isMultipleTouchEnabled = false backgroundColor = .red.withAlphaComponent(0.1) textContainer.lineFragmentPadding = 0 textContainer.maximumNumberOfLines = numberOfLines textContainer.lineBreakMode = lineBreakMode textContainer.layoutManager = layoutManager layoutManager.textStorage = textStorage layoutManager.addTextContainer(textContainer) textStorage.addLayoutManager(layoutManager) } override func layoutSubviews() { super.layoutSubviews() calculateRects() } private func calculateRects(){ linkRects.removeAll() guard let attributedString = attributedText else { return } textStorage.setAttributedString(attributedString) let labelSize = frame.size textContainer.size = labelSize layoutManager.ensureLayout(for: textContainer) let textBoundingBox = layoutManager.usedRect(for: textContainer) print("labelSize: \(labelSize)") print("textBoundingBox: \(textBoundingBox)") var wholeLineRanges = [NSRange]() layoutManager.enumerateLineFragments(forGlyphRange: NSRange(0 ..< layoutManager.numberOfGlyphs)) { _, rect, _, range, _ in wholeLineRanges.append(range) print("Whole line: \(rect), \(range)") } attributedString.enumerateAttribute(.link, in: NSRange(location: 0, length: attributedString.length)) { value, clickableRange, _ in if value != nil { var rectsForCurrentLink = [CGRect]() wholeLineRanges.forEach { wholeLineRange in if let linkPartIntersection = wholeLineRange.intersection(clickableRange) { var rectForLinkPart = layoutManager.boundingRect(forGlyphRange: linkPartIntersection, in: textContainer) rectForLinkPart.origin.y = rectForLinkPart.origin.y + (textContainer.size.height - textBoundingBox.height) / 2 // Adjust for vertical alignment rectsForCurrentLink.append(rectForLinkPart) print("Link rect: \(rectForLinkPart), \(linkPartIntersection)") } } if !rectsForCurrentLink.isEmpty { linkRects.append(rectsForCurrentLink) } } } print("linkRects: \(linkRects)") setNeedsDisplay() } } And I use this as such: let label = MyLabel() label.setContentHuggingPriority(.required, for: .vertical) label.setContentHuggingPriority(.required, for: .horizontal) view.addSubview(label) label.snp.makeConstraints { make in make.width.lessThanOrEqualTo(view.safeAreaLayoutGuide.snp.width).priority(.required) make.horizontalEdges.greaterThanOrEqualTo(view.safeAreaLayoutGuide).priority(.required) make.center.equalTo(view.safeAreaLayoutGuide).priority(.required) } let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .justified let s = NSMutableAttributedString(string: "Lorem Ipsum: ", attributes: [.font: UIFont.systemFont(ofSize: 17, weight: .regular), .paragraphStyle: paragraphStyle]) s.append(NSAttributedString(string: "This property controls the maximum number of lines to use in order to fit the label's text into its bounding rectangle.", attributes: [.link: URL(string: "https://news.ycombinator.com/") as Any, .foregroundColor: UIColor.link, .font: UIFont.systemFont(ofSize: 14, weight: .regular), .paragraphStyle: paragraphStyle])) label.attributedText = s Notice the paragraphStyle.alignment = .justified This results in: As you can see, the green rect background is starting a bit further to the right and also ending much further to the right. If I set the alignment to be .left or .center, then it gives me the correct rects: Also note that if I keep .justified but change the font size for the "Lorem Ipsom:" part to be a bit different, lets say 16 instead of 17, then it gives me the correct rect too: Also note that if we remove some word from the string, then also it starts giving correct rect. It seems like if the first line is too squished, then it reports wrong rects. Why is .justified text alignment giving me wrong rects? How can I fix it?
Topic: UI Frameworks SubTopic: UIKit
0
0
94
May ’25
SwiftUI: How to change `contentInset` of `List`
Hi, Is there any way of changing the contentInset (UIKit variant) of a List in SwiftUI? I do not see any APIs for doing so, the closest I gotten is to use safeAreaInset . While visually that works the UX is broken as you can no longer "scroll" from the gap made by the .safeAreaInset(edge:alignment:spacing:content:) I have subbmited a feedback suggestion: FB16866956
0
0
182
Mar ’25
NSPredicateEditorRowTemplate subviews layout
Hello everyone, I’d appreciate if anyone can tell me if there’s a way to actually control visual layout of subviews in a predicate editor row template. I have a predicate editor with custom row template subclasses, all created in code (not in IB) and it all works fine, but the problem are template (sub)views, which are not NSPopUpButton(s). As I select different items of popup buttons, effectively changing editor’s predicate property, those buttons seem to get resized according to some strange own logic, but the general the problem is that size (width) of controls, such are text fields and date pickers, gets unpredictable and they usually shrink, even though there is still a plenty of room in the template row width. Trying to resize any control in a row template by force (setFrame: or setFrameSize:) has no effect. I can show some screenshots and videos of the behaviour, as well as code samples, if necessary, but I’d like to ask first, maybe someone already knows what I’m talking about and provide some insights and solutions. Thanks in advance.
Topic: UI Frameworks SubTopic: AppKit
0
0
89
May ’25
ActiveLabel
Hey Everyone, I can't see to ActiveLabel as it says there is no active module. Please help me. Thanks, Ben import UIKit import ActiveLabel protocol TweetCellDelegate: AnyObject { func handleProfileImageTapped(_ cell: TweetCell) func handleReplyTapped(_ cell: TweetCell) func handleLikeTapped(_ cell: TweetCell) } class TweetCell: UICollectionViewCell {
0
0
263
Mar ’25
ApplePay QR code popup language
Hi Team, when launching an ApplePay session from a 3rd party browser where we get the QR code popup - is it possible to affect the popup's language? We are setting the button's language via locale parameter, but when the QR code pop's up it does not respect this setting (seems like it respects browser language). Button in Arabic Corresponding popup Browser language Arabic Coresponding popup I was unable to find anything in the documentation - could you please either point me to the relevant documentation or confirm/deny that it is possible to request a language for the popup via tjr javascript API? Kind regards Tomas
0
0
109
May ’25
How to replace default user location annotation with custom avatar in SwiftUI Map with selection parameter?
I'm implementing a Map with user location customization in SwiftUI using iOS 17+ MapKit APIs. When using the selection parameter with Map, the default blue dot user location becomes tappable but shows an empty annotation view. However, using UserAnnotation makes the location marker non-interactive. My code structure: import SwiftUI import MapKit struct UserAnnotationSample: View { @State private var position: MapCameraPosition = .userLocation(fallback: .automatic) @State private var selectedItem: MapSelection<MKMapItem>? var body: some View { Map(position: $position, selection: $selectedItem) { // UserAnnotation() } .mapControls { MapUserLocationButton() } } } Key questions: How can I replace the empty annotation view with a custom avatar when tapping the user location? Is there a way to make UserAnnotation interactive with selection? Should I use tag modifier for custom annotations? What's the proper way to associate selections?
0
0
328
Mar ’25
App Name Display
For now, my app name length is more than 20 characters, so the iPhone app name displays without a space, and uses the range operator to ensure showing the rest in the next line. Is it possible to show space and name with 2 lines?
Topic: UI Frameworks SubTopic: General Tags:
0
0
76
May ’25
Food-Truck-Sample navigation broken from Live Activity?
https://github.com/apple/sample-food-truck Hi! I'm seeing what looks like some weird navigation issue in the Food Truck app. It's from the Live Activity that should deep link to a specific point in the app. There seems be some state where the app is not linking to the correct component. Here are my repro steps on iPhone: Start live activity from OrderDetailView. Navigate to Sidebar component. Tap the Live Activity. App opens TruckView. The App should be opening the OrderDetailView for the Order that was passed to the Live Activity. This seems to work when the app is not currently on Sidebar. Any ideas? I'm testing this on iPhone OS 18.4.1. Is this an issue inside NavigationSplitView? Is this an issue with how Food Truck handles deeplinking?
0
0
68
May ’25
Tab bar inline icon text .compact mode in size classes in iPad in iOS 18..4.1
I am trying to do inline to icon and text in tab bar but it is not allowing me to do it in compact, but it showing me in regular mode , but in regular mode tab bar going at top in portrait mode , But my requirement is tab bar required in bottom with icon and text in inline it showed by horizontally but it showing to me stacked vertically, will you guide me on this so that I can push the build to live users.
0
0
116
May ’25
Can SwiftUI TextFields in a List on macOS be marked as always editable?
In SwiftUI's List, on macOS, if I embed a TextField then the text field is presented as non-editable. If the user clicks on the text and waits a short period of time, the text field will become editable. I'm aware this is generally the correct behaviour for macOS. However, is there a way in SwiftUI to supress this behaviour such that the TextField is always presented as being editable? I want a scrollable, List of editable text fields, much like how a Form is presented. The reason I'm not using a Form is because I want List's support for reordering by drag-and-drop (.onMove). Use Case A view that allows a user to compose a questionnaire. They are able to add and remove questions (rows) and each question is editable. They require drag-and-drop support so that they can reorder the questions.
0
0
137
May ’25