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

How to correctly use UIWindow.canResizeToFitContent
Can anyone show a simple code snippet about the usage of this property? I tried to create a UIWindow inside the main window, and set the canResizeToFitContent to true. However, when I added to it some sub view, the sub view didn't fit into the UIWindow. Actually, this sub view was located in another place far away from the UIWindow I created. Additionally, The documentation says, the content should be constraint-based. What does 'constraint-based' mean?
Topic: UI Frameworks SubTopic: UIKit
0
0
79
3w
UITabBar in iOS 26 is Too Big for Touch ID Devices
I do the majority of my test development on an iPhone 16 Pro in the iOS Simulator. As part of my UI rework to maintain compatibility with iOS 26 I decided to run on an older device with a small screen size for testing. The smallest device that supports iOS 26 is the iPhone SE 2nd Gen and 3rd Gen. Take a look at the image below: On the left is the iPhone SE 2nd Gen. On the right iPhone 16 Pro. It looks like the UITabBar which is from a UITabBarController is sized too tall. The actual Tab Bar itself is 62px while the container that houses it is 83px. Yes there should be some top/bottom space to allow for the Liquid Glass Effect to overlap as it often spills outside it's bounds but this feels like far too much. Looking at them side by side, the iPhone SE Tab Bar actually takes up more space which is not ideal for users who are working on a smaller screen to begin with and have less real estate. It looks like the bottom space is allowable room for the 'swipe to dismiss line' however these devices use Touch ID and that line is never present. Feels like the 83px for the Tab Bar should be reduced on these devices to allow for more useable screen real estate. Is this a design oversight as iOS 26 seems to be built predominantly for Face ID Devices? Just wondering if any Apple Design Engineers can chime in to see if this will be addressed in a future beta? The only way to change it at this stage is with a CGAffineTransform however this does not impact the '_UITabBarContainerWrapperView' that sits behind it. Also, on that note. The '_UITabBarContainerWrapperView' sometimes seems to be clear and other times displays a solid system background color. Is there anyway to control this? Many of my views both SwiftUI and UIKit have differing behaviour. My understanding is the idea of iOS 26 is for your app's content to be visible behind the Tab Bar, however the content is obscured by '_UITabBarContainerWrapperView' in many of my views and I can not figure out how to change that. Thanks!
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
110
3w
iOS 26 applying blur to UIView in navigationBar
Using a storyboard, I created a UIView containing an UIImageView and a UILabel, that I dragged into the navigation bar of one of my viewControllers. In my viewDidLoad I transform the view to move it down past the bounds of the navigation bar so its hidden initially navBarMiddleView.transform = .init(translationX: 0, y: 50) Then as the screen scrolls, I slowly move it up so it slides back into the middle of the navigationBar func scrollViewDidScroll(_ scrollView: UIScrollView) { let padding: CGFloat = 70 let adjustedOffset = (scrollView.contentOffset.y - padding) navBarMiddleView.transform = .init(translationX: 0, y: max(0, (50 - adjustedOffset))) } (The content is displayed in a collectionView cell as large content initially, and I want it to remain visible as the user scrolls down. So a mini view of the same data is moved up into the navigationBar) With iOS 26 the navigationBar is applying a blur effect to this view, even when its outside the bounds of the navigationBar, meaning the content its hovering on top of is slightly obscured. I don't know why this blur is being added, how do I remove it? I've tried the following based on recommendations from chatGPT but none have worked self.navigationController?.navigationBar.clipsToBounds = true self.navBarMiddleView.layer.allowsGroupOpacity = false self.navBarMiddleView.backgroundColor = .clear self.navBarMiddleView.isOpaque = true self.navBarMiddleView.layer.isOpaque = true I have my navigation bar setup with this appearence already: let navigationBarAppearance = UINavigationBarAppearance() navigationBarAppearance.configureWithOpaqueBackground() navigationBarAppearance.backgroundEffect = nil navigationBarAppearance.backgroundColor = UIColor.clear navigationBarAppearance.shadowColor = .clear navigationBarAppearance.titleTextAttributes = [ NSAttributedString.Key.foregroundColor: UIColor.colorNamed("Txt2"), NSAttributedString.Key.font: UIFont.custom(ofType: .bold, andSize: 20) ] UINavigationBar.appearance().standardAppearance = navigationBarAppearance UINavigationBar.appearance().compactAppearance = navigationBarAppearance UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
1
0
80
3w
Detents Size Differently on Touch ID Devices in iOS 26
When working with modal sheet views in iOS 26 I animate changes to detent size like this: if let sheet = self.sheetPresentationController { let newDetent = 400 sheet.animateChanges { sheet.invalidateDetents() sheet.detents = [.custom(resolver: { context in newDetent })] } } What I have found is that when using a Touch ID Device the input detent will be smaller when the system presents it. If I set the detent size to be 400, on an iPhone 16 Pro it will be 400px but on an iPhone SE 2nd Gen it will be 366. It seems to be consistently 34px shorter on devices with a Touch ID Square Shaped Screen. This 34px corresponds to the bottom safe area. This feels like a bug to me. I would expect the detent size to match what I assign on all devices. I will monitor if this is fixed in a future beta but it is present as of iOS 26 Beta 5. In the meantime I have built this helper function which will then correctly size it on all devices: static func getDetent(basedOn inputValue: Double) -> CGFloat { if let window = UIApplication.shared.windows.first { if window.safeAreaInsets.bottom > 0 { // Face ID Device, Bottom Inset of 34 return inputValue } else { // Touch ID Device, Bottom Inset of 0 return inputValue + 34 } } else { // Fallback, Return Input Value return inputValue } } This impacts when animating detents as per above but also when presenting a Sheet View for the first time and assigning a custom detent. Thanks!
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
65
3w
ios26 NumberPad keyboard issue on iPad
On an iPad running iOS26, there is an issue with the numberPad keyboard I have a UITextField with a keyboard type of .numberPad When I first tap in the field, a new number pad with just numbers (similar to the one that shows up on iPhone) shows up. When I tap again in the field, that number pad goes away. When I tap in the field again, the full keyboard with numbers etc shows up (this is the one that used to always show up pre-iOS26)
Topic: UI Frameworks SubTopic: UIKit
2
0
73
3w
UIMainMenuSystem - disable elements
Hi, I am trying to implement the UIMainMenuSystem for showing the menu bar in my iPad app in iOS26. I would like to be able to disable some elements when a particular UIViewController is displayed on the screen, and I can't figure out the best way to do this. I tried overriding the 'validateCommand' method in my view controller, but it doesn't seem to invoke the validation for menu items that are in the main menu. Any tips on how to do this?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
50
3w
[iOS18]The transition animation stops and cannot be interacted with
The app becomes unresponsive when pushing a new page. The screen is covered by the _UIParallaxOverlayView class, blocking all gestures. Are there any scenarios where the transition animation might suddenly stop mid-process? Or could you provide more information to help me troubleshoot this issue? I noticed: When the issue occurs, the FromViewController is displayed on the screen. The ToViewController also exists in the view tree, but it's not visible on the screen. _UIParallaxOverlayView only appears on iOS 18 and above. The animation appears to be controlled by +[UIView _fluidParallaxTransitionsEnabledWithTraitCollection:], which is _os_feature_enabled_impl("UIKit", "fluid_parallax_transitions"). Reference
0
0
44
3w
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
105
3w
Is there a tech note for menuBuilder?
I'm trying to piece together how I should reason about multiple windows, activating menus and items. For instance, I have an email command. If a document is open, it emails just that document. If the collection view holding that document is open, it generates an attachment representing the collection. (this happens with buttons right now but this really feels like a menu item) How do I tell which window is active (document/collection) in order to have the right menu item available. If the user is adding a document I don't want the "new" command open, I only want one editing view. I saw sample code to include or remove commands but not disable them. I feel like there's a whole conceptual layer I want to understand with the interplay with scenes but don't know where to look for documentation. I searched here but there's hardly any threads on this. TIA
Topic: UI Frameworks SubTopic: UIKit
7
0
127
3w
'editButtonItem.title' Cannot Be Updated in iOS 26
In iOS 26, I found that editButtonItem.title cannot be programmatically updated as before. Even when explicitly setting the title in viewWillAppear or inside setEditing(_:animated:), the text remains the default “Edit” / “☑️”. Here is a minimal reproducible example: import UIKit class ViewController: UIViewController { private let infoLabel: UILabel = { let l = UILabel() l.text = "uneditable" l.font = .systemFont(ofSize: 28, weight: .medium) l.textAlignment = .center l.translatesAutoresizingMaskIntoConstraints = false return l }() private let textField: UITextField = { let tf = UITextField() tf.placeholder = "This will become effective when you edit it." tf.borderStyle = .roundedRect tf.translatesAutoresizingMaskIntoConstraints = false tf.isEnabled = false return tf }() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemBackground navigationItem.title = "sample" navigationItem.rightBarButtonItem = editButtonItem setupLayout() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) updateEditButtonTitle() } private func setupLayout() { view.addSubview(infoLabel) view.addSubview(textField) NSLayoutConstraint.activate([ infoLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor), infoLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -40), textField.topAnchor.constraint(equalTo: infoLabel.bottomAnchor, constant: 20), textField.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor), textField.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor), textField.heightAnchor.constraint(equalToConstant: 44), ]) } override func setEditing(_ editing: Bool, animated: Bool) { super.setEditing(editing, animated: animated) textField.isEnabled = editing infoLabel.text = editing ? "editable" : "uneditable" if editing { textField.becomeFirstResponder() } else { textField.resignFirstResponder() } updateEditButtonTitle() } private func updateEditButtonTitle() { editButtonItem.title = isEditing ? "done" : "edit" } } Expected behavior Changing editButtonItem.title should update the displayed title of the bar button item. Actual behavior (iOS 26) The title remains the default “Edit” / “☑️” text, ignoring programmatic updates. This worked in previous iOS versions. It appears that in iOS 26 the system may be overriding editButtonItem.title automatically, preventing custom titles. Is this an intentional change, or a bug introduced in iOS 26?
Topic: UI Frameworks SubTopic: UIKit
1
0
58
3w
WKWebView touch event listener misdirect in iOS 18.5
Hello, after the IOS update 18.5, all elements with an touch-event listener inside a wkWebview seem to offset a touch-events origin x and y location by a factor of 0.666. Triggering any other element with an touch-event listener at that location instead. If there is not on an element with an touch-event listener at the offset location, nothing happens. Only if the offset origin is coincidentally still inside the actually touched element, the touch-event gets dispatched correctly. This effects only the event listener: "touchstart", "touchmove" and "touchend". click-event listeners still work, and trigger on the correct element. Confusing are the contents of the touch-events being dispatched. The attributes "pageX" and "pageY" report the correct position touched, yet "target" gives the (wrong) Element at the offset location. The offset location can be found in "targetTouches[0].pageX" and "targetTouches[0].pageY". The offset factor can be influenced by the "width" value of this header tag: "". If the width value is 240 the factor changes to 1.333, and the value 320 actually fixes this offset completely. Device: Iphone XS with IOS 18.5 <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="content-type"/> <!--<meta name="viewport" content="width=240, user-scalable=no"/>--> <meta name="apple-mobile-web-app-capable" content="yes"/> <meta name="apple-mobile-web-app-status-bar-style" content="black"/> <meta name="format-detection" content="telephone=no"/> <link rel="apple-touch-icon" href="applogo"/> </head> <body> <style> div{ height:70px; width: 100%; margin-top: 7px; background-color: #f7f7f7; } </style> <div id="Feedback" style="background-color:white;font-size:10px;"></div> <div id="A" ontouchstart="insertTouchFeedback">Element A</div> <div id="B">Element B</div> <div id="C">Element C</div> <div id="D">Element D</div> <div id="E">Element E</div> <div id="F">Element F</div> <div id="G">Element G</div> <script> const feedback = document.getElementById("Feedback"); function insertTouchFeedback(event){ const offsetX = event.pageX - event.targetTouches[0].pageX; const offsetY = event.pageY - event.targetTouches[0].pageY; feedback.innerHTML = ` Hit on ${event.pageX}x${event.pageY} <br/> Actually triggers "${event.target.innerHTML}" at ${event.targetTouches[0].pageX}x${event.targetTouches[0].pageY} <br/> Offset ${offsetX}x${offsetY} <br/> Factor ${event.targetTouches[0].pageX / event.pageX} x ${event.targetTouches[0].pageY / event.pageY} `; } document.getElementById("A").addEventListener("touchstart", insertTouchFeedback); document.getElementById("B").addEventListener("touchstart", insertTouchFeedback); document.getElementById("C").addEventListener("touchstart", insertTouchFeedback); document.getElementById("D").addEventListener("touchstart", insertTouchFeedback); document.getElementById("E").addEventListener("touchstart", insertTouchFeedback); document.getElementById("F").addEventListener("touchstart", insertTouchFeedback); document.getElementById("G").addEventListener("touchstart", insertTouchFeedback); </script> </body> </html> We use WKWebView within Objective-C. Any idea whet goes wrong would be great! Thanks!
Topic: UI Frameworks SubTopic: UIKit
3
0
89
3w
CPNavigationAlert image size very small with long title variant
I am using CPNavigationAlert and am getting a specific name for the title, so I do not have more than one variant. Sometimes, the variant title is longer, which for some reason makes the image very small. I have tried to make sure to keep displayScale in mind: let maximumImageSize = CPListItem.maximumImageSize let displayScale = self.interfaceController?.carTraitCollection.displayScale ?? 2 let imageSize = CGSizeMake(maximumImageSize.width * displayScale, maximumImageSize.width * displayScale) let image = CarPlayMapUtility().getIconAlertImage(item: item, frame: imageSize) If the titleVariants is shorter, the image is displayed corrected. If it is longer, the image might be extremely small or not shown at all. Is this expected?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
53
3w
UISearchController cannot become first responder when switching to a search tab
I would like my users to be able to switch to the search tab (in the sidebar) on iPad and immediately start typing. This is not possible. Calling becomeFirstResponder in viewDidLoad and viewWillAppear does not work. Only in viewDidAppear it does, but that comes with a significant delay between switching to the tab and the search field becoming active. Is there something else I can do? FB19588765 let homeTab = UITab( title: "Home", image: UIImage(systemName: "house"), identifier: "Home" ) { _ in UINavigationController(rootViewController: ViewController()) } let searchTab = UISearchTab { _ in UINavigationController(rootViewController: SearchViewController()) } let tabBarController = UITabBarController(tabs: [ homeTab, searchTab ]) tabBarController.mode = .tabSidebar class SearchViewController: UIViewController { let searchController = UISearchController(searchResultsController: nil) override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = .systemBackground self.title = "Search" self.navigationItem.searchController = searchController self.navigationItem.preferredSearchBarPlacement = .integratedCentered searchController.becomeFirstResponder() // Does not work. searchController.searchBar.becomeFirstResponder() // Does not work. } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) searchController.searchBar.becomeFirstResponder() // Does not work. } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) searchController.searchBar.becomeFirstResponder() // Works. But comes with a significant delay. } }
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
65
3w
UISegmentedControl Not Switching Segments on iOS Beta 26
While testing my application on iOS beta 26, I am experiencing issues with the native UISegmentedControl component from UIKit. After implementing the control, I noticed that I am unable to switch to the second segment option—the selection remains fixed on the first segment regardless of user interaction. I have already reviewed the initial configuration of the control, the addition of the segments, and the implementation of the target-action, but the issue persists. I would like to understand what could be causing this behavior and if there are any specific adjustments or workarounds for iOS 26. I created a minimal application containing only a UISegmentedControl to clearly demonstrate the issue.
18
4
541
3w