Construct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.

UIKit Documentation

Posts under UIKit subtopic

Post

Replies

Boosts

Views

Activity

UIAlertAction.isEnabled = false Has No Visual Effect on iOS 26 (Action Still Looks Enabled)
Hi all, I'm running into a UIKit issue specific to iOS 26 (Xcode 26 Beta 4) where UIAlertAction buttons that are disabled using .isEnabled = false do not appear visually disabled. The alert still shows the action with full opacity and default styling, making it look like the button is tappable — even though it isn't. ❗ Issue: On iOS 26, disabled actions in UIAlertController no longer appear dimmed or inactive. This is a visual regression compared to iOS 18 and earlier, where disabled actions would automatically appear grayed out and visually distinct.
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
102
Jul ’25
UIAlertAction.isEnabled = false Has No Visual Effect on iOS 26 (Action Still Looks Enabled)
Hi all, I'm running into a UIKit issue specific to iOS 26 (Xcode 26 Beta 4) where UIAlertAction buttons that are disabled using .isEnabled = false do not appear visually disabled. The alert still shows the action with full opacity and default styling, making it look like the button is tappable — even though it isn't. ❗ Issue: On iOS 26, disabled actions in UIAlertController no longer appear dimmed or inactive. This is a visual regression compared to iOS 17 and earlier, where disabled actions would automatically appear grayed out and visually distinct.
Topic: UI Frameworks SubTopic: UIKit
1
0
42
Jul ’25
RealityKit battery drain intuition?
Hi all, Is there a standard, good intuition about RealityKit battery drain vs how the Xcode profiler tends to display things? I have a realitykit ARview that i have permanently in my view hierarchy and the profiler is saying constantly 40% CPU spin, ~160mb increase of memory usage compared to when not using this view, and battery increased from Low to middle of the yellow bar for "high". Yet the actual battery drain attributed to my app is basically an order of magnitude lower than the battery drain of something like Tiktok for the same amount of foreground time (15% vs 2%) So I'm a little confused whether or not to trust the Xcode battery profiler when working with RealityKit and ARViews (unless Tiktok is in very high usage all the time!). Is this a largely ignorable signal, and more generally, how useful is this profiler? Doesn't seem immediately intuitive to me at first use. Thanks!
0
0
127
Jul ’25
App no longer runs in latest Xcode 26 Beta 4 17A5285i
Since installing the latest Xcode Beta (version 26.0 beta 4 17A5285i), it no longer runs my app on iPhone 11 and also not on iPad 10.2, both running iOS 18.5. The following code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions ... // Preload both Tabbar Views NSArray* tabViewControllers = _tabBarController.viewControllers; _firstViewCntrl = (FirstViewController *)[tabViewControllers objectAtIndex:0]; _secndViewCntrl = (SecondViewController *)[tabViewControllers objectAtIndex:1]; UIView *dummy1 __unused; UIView *dummy2 __unused; dummy2 = _secndViewCntrl.view; // Triggers viewDidLoad <<<<< CRASH will crash the app (the problem is with the 'view' attribute): *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named TtGC5UIKit17UICoreHostingViewVCS_21ToolbarVisualProvider8RootView because no class named TtGC5UIKit17UICoreHostingViewVCS_21ToolbarVisualProvider8RootView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)' When I instead choose the Simulator (iPhone 16 Rosetta) as a destination, the app runs fine and the above assignment will trigger the viewDidLoad method of the second ViewController. So the Rosetta simulator runs fine, but the physical device fails. The debugger console illustrates the differences between stable and beta Xcode versions (both on physical device): Xcode Version 16.4 (16F6) from AppStore (app runs fine): (lldb) p _secndViewCntrl.view (UIView *) 0x0000000108366d00 Xcode Beta version 26.0 beta 4 17A5285i (app now crashes): (lldb) p _secndViewCntrl.view error: Execution was interrupted, reason: internal ObjC exception breakpoint(-9).. The process has been returned to the state before expression evaluation. Any ideas?
Topic: UI Frameworks SubTopic: UIKit
4
0
266
Jul ’25
How to customize UIActivityViewController
We are currently developing an enterprise iOS application and are in the process of implementing Data Leakage Protection (DLP) features. As part of this effort, we need to control the available actions and target applications presented within the UIActivityViewController. Specifically, we would like to programmatically filter or restrict certain activities and destination apps shown in the share sheet based on user-specific permissions. These permissions will be dynamically evaluated and updated at runtime. This type of functionality is supported by the Microsoft Intune SDK. However, our objective is to implement this behavior natively within our application without relying on any third-party libraries. Could you please advise on the recommended approach or available APIs to achieve this level of control over the UIActivityViewController?
4
0
255
Jul ’25
For the property modifiers of XIB controls, should we use strong or weak?
In our current code, the properties of XIB controls are added with weak. However, we encounter some crashes due to accessing wild pointers of controls when a memory warning occurs. Colleagues from our architecture team said that they had specifically consulted Apple's technical staff before, and the reply was that strong should be used for modification, as it would make the memory more stable. They also mentioned that the statement in the official documentation is incorrect and hasn't been updated. May I ask whether strong or weak should be used for XIB control properties? What is your latest standard answer?
Topic: UI Frameworks SubTopic: UIKit Tags:
4
0
110
Jul ’25
Incorrect safeAreaInsets.top on iPhone SE (2nd/3rd gen) – iOS 26 Beta
On iPhone SE (2nd/3rd generation) running iOS 26 beta , the safeAreaInsets.top unexpectedly returns 0 instead of the expected 20 points, causing UI elements that rely on safe area layout to be overlapped by the status bar. You can see that i works fine with iOS 18, whereas iOS 26 the status bar is overlapped. Is this a known bug or there is new API changes that I might not be aware of.
Topic: UI Frameworks SubTopic: UIKit Tags:
3
0
341
Jul ’25
How to get UITextView to fit inside container, AND auto wrap
I am currently having an issue in where whenever I place a UITextView with text that's long, it simply pushes past the width of the container it is in, and when I do try and set a width, it does auto wrap and ignores that. I do not come from UIKit and come from SwiftUI, through a mix of ChatGPT and Stack overflow, I have come up with this solution, however, are there any better/simpler ones, I dont want to have to use expensive GeoReaders just to get a width. struct AutoDetectedPhoneNumberView: UIViewRepresentable { let text: String var width: CGFloat func makeUIView(context: Context) -> UITextView { let textView = UITextView() textView.dataDetectorTypes = [.phoneNumber] textView.isEditable = false textView.isScrollEnabled = false textView.backgroundColor = .clear textView.font = UIFont.systemFont(ofSize: 16) textView.textContainer.lineBreakMode = .byWordWrapping textView.translatesAutoresizingMaskIntoConstraints = false print(width) NSLayoutConstraint.activate([ textView.widthAnchor.constraint(equalToConstant: width) ]) return textView } func updateUIView(_ uiView: UITextView, context: Context) { uiView.text = text } } GeometryReader { geo in AutoDetectedPhoneNumberView(text: phone, width: geo.size.width) }
0
0
81
Jul ’25
Right bar button items in iOS 26 visual presentation
I have attached two images of two screens below. In one screen, bar button are enclosed within separate, distinct, rounded-rectangle 'liquid glass' capsules. In other screen, bar buttons are enclosed within separate, distinct, rounded-rectangle "liquid glass" capsules. They are not visually merged into one larger capsule. Both are having same code. But why it is not same ?
1
0
94
Jul ’25
Large title is not visible in iOS 26
I am using below code to change navigationBar bg colour, but the text is hidden in large title. It works fine in previous versions. Kindly refer below code and attached images. Code: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController?.navigationBar.prefersLargeTitles = true navigationItem.largeTitleDisplayMode = .always let appearance = UINavigationBarAppearance() appearance.backgroundColor = UIColor( red: 0.101961, green: 0.439216, blue: 0.388235, alpha: 1.0 ) navigationController?.navigationBar.standardAppearance = appearance navigationController?.navigationBar.scrollEdgeAppearance = appearance navigationController?.navigationBar.compactAppearance = appearance } Referenced images:
3
2
200
Jul ’25
Positioning an image
This may seem really basic, but I'm not using the screen designer, I'm doing this old school (programmatically). I think I'm using Swift 5 (not actually sure). This image may help. So I created my own UIImageView class called GenericImage class GenericImage: UIImageView, @unchecked Sendable { ... } I create the GenericImage class and add it to the View Controller. Then I load the image and set some positioning within my GenericImage class let imageView = GenericImage(frame: CGRect.zero) self.view.addSubview(imageView) imageView.processResponse(componentDictionary ) In the GenericImage class I load the image and set some constraints. self.imageFromURL(urlString: imageUrl) self.translatesAutoresizingMaskIntoConstraints = false self.contentMode = .scaleAspectFit self.widthAnchor.constraint(equalToConstant: 100.0).isActive = true self.heightAnchor.constraint(equalToConstant: 100.0).isActive = true self.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true self.topAnchor.constraint(equalTo: self.centerYAnchor).isActive = true The image is displayed at the top left of the screen. I'm guessing that the code I have written should center the image on the screen. However, while I would like to know how to center the image, I also want to be able to position it at a specific place on the screen, using points (or pixels). Any suggestions?
3
0
120
Jul ’25
UIKit crash on app built with Xcode 26 but run on iOS 18.X
An app built on Xcode 26 (beta4) presents various UIViewCOntrollers. Presentation of any UIViewController that contains a UIToolbar leads to a UIKit crash when run on an iOS 18.5 device, it does not crash when run on iOS 26. The exception logged: *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named TtGC5UIKit17UICoreHostingViewVCS_21ToolbarVisualProvider8RootView because no class named TtGC5UIKit17UICoreHostingViewVCS_21ToolbarVisualProvider8RootView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)' Anyone else seen this? I've submitted a bug report via Feedback Assistant, including a minimal Xcode workspace that reproduces the crash, hoping this will get some attention.
13
3
448
Jul ’25
Getting two searchBar in iOS 26.0
Hi team, while i am using below code, i am getting two searchBar at top & bottom. Kindly refer below code & attached image Code: override func viewDidLoad() { super.viewDidLoad() title = "Test Data" setupSearchData() DispatchQueue.main.asyncAfter(deadline: .now() + 2) { self.setupSearchData() } } func setupSearchData() { navigationController?.navigationBar.prefersLargeTitles = false let searchController = UISearchController(searchResultsController: nil) navigationItem.searchController = searchController } It is working fine for other iOS versions. In my real useCase, i will refresh screen after API completed, then this issue occurred in my app.
2
0
84
Jul ’25
iOS 26 UISplitViewController in dark mode appearance.
We have encountered a problem on iOS 26. When switching to dark mode, the color of all subviews (font color, background color, etc.) of the Sidebar (Primary View) of UISplitViewController will not change. For example, if it is set to the color of UIColor.label, it will always be black and will not be white in dark mode. On Xcode, just create a UISplitViewController in Storyboard without changing any settings, and run it directly to see the following: The title of the Navigation Bar defaults to the label color, and it is still black after switching to dark mode. There is no such problem in the Secondary View or other places. This problem has occurred since iOS 26 beta 3, and iOS 26 beta 4 is now the same. But beta 1 and beta 2 have no problem. I'm not sure if this is a bug, or if there is something that needs to be changed to adapt to iOS 26?
Topic: UI Frameworks SubTopic: UIKit Tags:
7
4
515
Jul ’25
OS 26 with CNContactViewController issue
when using CNContactViewController to present a contact detail info, the system CNContactViewController appear some UI issues. On iOS 26, the Poster avatar overlaps with the title "Edit device contact" On iPadOS26 with device(not simulator), when click 'Add photo', the CNContactViewController will auto dismiss, and the console output some error log: below are the sample code: AppDelegate.swift: import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { let window: UIWindow = UIWindow() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let vc = SplitViewController(primary: TabBarViewController(), secondary: ViewController()) window.rootViewController = vc window.makeKeyAndVisible() return true } } SplitViewController.swift: import UIKit class SplitViewController: UISplitViewController { init(primary: UIViewController, secondary: UIViewController) { super.init(nibName: nil, bundle: nil) preferredDisplayMode = .oneBesideSecondary presentsWithGesture = false delegate = self viewControllers = [primary, secondary] } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() } } extension SplitViewController: UISplitViewControllerDelegate { } TabBarViewController.swift: import UIKit class BaseViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } } class HomeViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .red navigationItem.title = "Home" tabBarItem = UITabBarItem(title: "Home", image: UIImage(systemName: "house"), tag: 0) } } class TabBarViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() let homeVC = HomeViewController() let homeNav = UINavigationController(rootViewController: homeVC) viewControllers = [homeNav] ContactManager.shared.getAllContactIdentifiers() } } ViewController.swift: import UIKit import Contacts import ContactsUI class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemPink let button = UIButton(frame: .zero) button.backgroundColor = .orange button.setTitle("show contact", for: .normal) button.addTarget(self, action: #selector(showContactInfo), for: .touchUpInside) button.translatesAutoresizingMaskIntoConstraints = false view.addSubview(button) button.widthAnchor.constraint(equalToConstant: 200).isActive = true button.heightAnchor.constraint(equalToConstant: 60).isActive = true button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true } @objc private func showContactInfo() { print("showContactInfo") let identifier = ContactManager.shared.identifiers[0] let currentContact = try? CNContactStore().unifiedContact(withIdentifier: identifier, keysToFetch: [CNContactViewController.descriptorForRequiredKeys()]) guard let contact: CNMutableContact = currentContact?.mutableCopy() as? CNMutableContact else { return } let vc = CNContactViewController(forNewContact: contact) vc.delegate = self vc.title = "Edit Device Contact" vc.allowsActions = false vc.contactStore = CNContactStore() let navigationVC: UINavigationController = UINavigationController(rootViewController: vc) let appDelegate = UIApplication.shared.delegate as? AppDelegate appDelegate?.window.rootViewController?.present(navigationVC, animated: true, completion: nil) } } extension ViewController: CNContactViewControllerDelegate { public func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) { viewController.dismiss(animated: true, completion: nil) } }
1
0
168
Jul ’25
New iPadOS 26 beta4 crash in `UISplitViewController`
Sample Project In iPadOS 26 beta4, when a UISplitViewController transitions to compact layout and proposes the secondary view controller, a crash occurs: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Layout requested for visible navigation bar, <UINavigationBar: 0x1018205b0; frame = (0 0; 320 54); opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0x600000d37cc0>; layer = <CALayer: 0x600000d13390>> delegate=0x102826600, when the top item belongs to a different navigation bar. topItem = <UINavigationItem: 0x101af3b20> title='Detail' style=navigator rightBarButtonItems=0x600000011e10, navigation bar = <UINavigationBar: 0x101817680; frame = (0 0; 320 54); opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0x600000d12310>; layer = <CALayer: 0x600000d116b0>> delegate=0x102826000, possibly from a client attempt to nest wrapped navigation controllers.' When we show the primary view, there is no crash. Similarly, there is no crash on beta-3. To reproduce the crash in the demo project: Launch the project on an iPad. "Try the Demo" Tap "List-Detail Pattern" To trigger the crash, select any of the list items and switch the app to a compact layout. The crash occurs because the app will attempt to propose the secondary view controller. To avoid the crasah, refrain from selecting an item in the list and switch to the compact layout. The app will not crash because it will attempt to propose the primary view controller.
Topic: UI Frameworks SubTopic: UIKit
1
1
167
Jul ’25