Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

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

Should iPadOS 18's UITabBarController work with more than 7 tabs?
Is it expected that UITabBarController in iPadOS 18 beta 2 should be working with more than 7 tabs yet, or is this still a work-in-progress on Apple's end? Currently, if I create a UITabBarController and configure it with more than 7 root tabs (i.e. enough to trigger the "more" tab in previous iPadOS versions) using the new UITab API, any tab after the seventh one is effectively not selectable: If the view is at a horizontally regular width: When you select via the new floating tab bar or the sidebar, the tab / sidebar item itself does become selected, but the actually displayed view controller remains unchanged. If you switch the window to a horizontally compact width, it switches to the old-style of tab bar, and the "More" tab with its moreNavigationController functionality becomes visible, and from there you select and actually present one of the 'excess' tabs. (Note: there appear to be some push/pop animation glitches when transitioning between the moreNavigationController and the tab's view controller) Then if you're in one of those 'more' tabs and then switch the window back to horizontally regular width: The currently displayed view controller (e.g. "view controller 9") is still shown, and the "More" back button along with it The new tab bar controls will act like some other tab is selected: specifically, whichever tab was selected when the window was last in the horizontally regular width mode If you tap on the "More" back button, you get the moreNavigationController and from that you can select any of the other overflow tabs (all the while with the old old tab showing as selected in the tab bar) If the moreNavigationController's tab list is visible, and you select one of the overflow tabs from the new tab bar or side bar, the correct view controller will be pushed onto the moreNavigationController's stack and show as selected in the new tab bar / side bar. (Hooray!) But this only appears to work specifically when the moreNavigationController's tab list is visible and there's nothing else on that navigation stack. Fundamentally, it feels like the work to sync the new tab management state with the moreNavigationController state isn't finished yet? But I've looked at the beta release notes and not seen any mention of these limitations. My questions, before I file any feedbacks: Are these known issues that are still being worked on? Is it Apple's intent that >7 root tabs should work by the time of iPadOS 18's release?
Topic: UI Frameworks SubTopic: UIKit
2
0
1k
Jun ’24
How on earth do I get the actual dimensions of a presented modal view on iPad?
This is the stupidest thing that should be so easy. I simply present a view controller using: [self presentViewController:settingsView animated:YES completion:^(){ }]; Then in the code for the view controller being presented, I want to know it's width, which should be stupidly simple using: const int viewWidth = self.view.frame.size.width; HOWEVER, this gives me a value that is the same as the parent view's width, yet on iPad at least this view is visibly smaller than the parent/presenting view (as it is hovering over it with the view visible around the edges behind it). I have tried every stupid thing I can find within the parent view and view controller code that mentions margins and insets and whatnot, but nothing seems to give me the actual stupid value of the stupid presented view's visible dimensions! Any ideas? The iPad is on iPadOS 15.3.1, might try installing a newer version and see if this is some bug in this particular version of the OS.
Topic: UI Frameworks SubTopic: UIKit
4
0
858
Jun ’24
How to implement UITextItem in custom text view with UITextInput and TextKit2
Hi Apple, I'm implementing a custom text view by conforming to UITextInput and backing it with TextKit2. However, I like the UITextItem feature of the default UITextView. Can I get some guidance on how to reimplement it? Are we looking at overlaying UIMenu buttons? Or some API where I can display a UIMenu at a rect I specify? Hopefully, it is not some kind of private API? Thanks for the help in advance.
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
572
Jul ’24
Correct Collection View "stretchy header" implementation?
Hello, I have the following subclass of UICompositionalCollectionViewLayout to get the stretchy header effect as shown below. It works quite well, but I don't really have an experience with creating custom layouts so I thought I'd ask if maybe my implementation doesn't have some important flaws. I once ran into persistent layout loop crash with this and I am not sure what exactly I changed but it stopped happening. However since I am using this layout on important screen, I would like to make sure there isn't obvious potential for the layout loop crash happening in App Store version. I am particularly unsure about the shouldInvalidateLayout implementation. Originally I was returning true all the time, but decided to change it and only force invalidation for negative content offset which is when my header is supposed to stretch. Here is the full code: final class StretchyCompositionalLayout: UICollectionViewCompositionalLayout { override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { var attrs = super.layoutAttributesForElements(in: rect) ?? [] guard let collectionView = collectionView else { return attrs } let contentOffset = collectionView.contentOffset.y guard contentOffset < 0 else { return attrs } var newAttributes: UICollectionViewLayoutAttributes? attrs.forEach({ attribute in if attribute.indexPath.section == 0 && attribute.indexPath.item == 0 { let startFrame = attribute.frame newAttributes = attribute.copy() as? UICollectionViewLayoutAttributes let newFrame: CGRect = .init(x: 0, y: contentOffset, width: startFrame.width, height: startFrame.height - contentOffset) newAttributes?.frame = newFrame } }) if let new = newAttributes { attrs.removeAll { attr in return attr.indexPath.section == 0 && attr.indexPath.item == 0 } attrs.insert(new, at: 0) } return attrs } override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { guard let attributes = super.layoutAttributesForItem(at: indexPath) else { return nil } let contentOffset = collectionView?.contentOffset.y ?? 1 guard contentOffset < 0 else { return attributes } if indexPath.section == 0 && indexPath.item == 0 { let attributes = attributes.copy() as? UICollectionViewLayoutAttributes ?? attributes let startFrame = attributes.frame let newFrame: CGRect = .init(x: 0, y: contentOffset, width: startFrame.width, height: startFrame.height - contentOffset) attributes.frame = newFrame return attributes } else { return super.layoutAttributesForItem(at: indexPath) } } override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { let contentOffset = collectionView?.contentOffset.y ?? 1 // There is visual glitch when 0 is used in this condition if contentOffset < 1 { return true } else { return super.shouldInvalidateLayout(forBoundsChange: newBounds) } } } Any feedback welcome!
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
511
Jul ’24
Screen Sleep Issue When Removing Vision Pro
Hello VisionOS Developer Community, I am currently working on a demo application for VisionOS, tailored for the Vision Pro. In my application, I have implemented a feature to prevent the screen from sleeping using the following code: UIApplication.shared.isIdleTimerDisabled = true This works perfectly on iOS, ensuring the screen remains active regardless of other system settings. However, I've run into a snag with VisionOS. Even with isIdleTimerDisabled set to true, the screen still sleeps when I take off the Vision Pro.
0
0
420
Jul ’24
Screen Sleep Issue When Removing Vision Pro
Hello VisionOS Developer Community, I am currently working on a demo application for VisionOS, tailored for the Vision Pro. In my application, I have implemented a feature to prevent the screen from sleeping using the following code: UIApplication.shared.isIdleTimerDisabled = true This works perfectly on iOS, ensuring the screen remains active regardless of other system settings. However, I've run into a snag with VisionOS. Even with isIdleTimerDisabled set to true, the screen still sleeps when I take off the Vision Pro.
1
0
466
Jul ’24
UIAccessibility.Notification concurrency errors with Xcode 16 beta 2
I am running into some Swift 6 concurrency errors that I think are due to an odd oversight in the UIAccessibility Swift interface. There are a number of constants defined in here for various things, most of which are marked "let" (appropriately). However, the constants for notifications in extension UIAccessibility.Notification are all marked as var for some reason. For example: public static var pageScrolled: UIAccessibility.Notification Because it is var, not let, anytime I try to access it, I get a concurrency violation. I am baffled as to how I am supposed to work around this. For example, this line of code: UIAccessibility.post(notification: .pageScrolled, argument: "test") gives the error: "Reference to static property 'pageScrolled' is not concurrency-safe because it involves shared mutable state" I can't for the life of me figure out how to work around this. I guess maybe define my own constant somewhere and suss out the rawValue somehow for now? This really needs to be fixed in the SDK.
Topic: UI Frameworks SubTopic: UIKit Tags:
5
0
857
Jul ’24
Can I change the CPListItem text color?
I am working on a communications CarPlay app and am implementating a calling tab. I want to display calls that are missed in red text vs answered in the default text color. Is there a way to change the color of CPListItem.text or is this not allowed by design?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
590
Jul ’24
Markdown Parsing Adding Unexpected Paragraph Attributes
I am looking to support rendering markdown text while adding corporate branding styles (typography and colors for headers specified by the design team, etc). All was going well until I encountered Ordered List and began seeing some unexpected behavior. Lets take for example some sample markdown as shown below. let sampleMarkdown: String = """ # Ordered List Test This is some sample markdown used to test ordered lists. 1. Line item one of a sample markdown ordered list. 2. This is the second line item of a sample markdown ordered list. 3. And finally, the third line item of a sample markdown ordered list. """ Now, let's say for each item in the ordered list, I would like to assign a random foreground color to the text. This is straightforward as I can loop over the runs of an attributed string and should I encounter an intentType.kind of .orderedList I can apply the random foreground color as so with clode along the lines of such: for run in pulseAttributedString.runs { if let presentationIntent = run.presentationIntent { for intentType in presentationIntent.components { switch intentType.kind { case .orderedList: let colors: [UIColor] = [.green, .systemPink, ...] container[AttributeScopes.UIKitAttributes.ForegroundColorAttribute.self] = colors.randomElement() } } } } Upon setting the random foreground color to the attribute container, and running in the Simulator you can see the following output. This is very much close to what I'd expect although frustratingly the parser seemed to have stripped out the 1. 2. etc. I'm not sure what the reasoning for that is, or why the .orderedList does not have an associated value representing the index of the line item in the list, similar to how case header(level: Int) includes an associated value for header level. Upon closer inspection, I also see that there is another presentation intent kind of case listItem(ordinal: Int). When I add a case in my switch statement for listItem I see it too is included within the presentation intent components. With that said, I need to restore the 1., 2. etc, would I use case listItem(ordinal: Int) or .orderedList. And what would be the difference between the two? Would someone be able to explain that to me since the documentation for listemItem seems to make no effort to do so. This now leads me to the next issue I was encountering where if I then add emphasis to some words within the ordered list, essentially the same sample markdown above but with emphais on the word one and second: let sampleMarkdown: String = """ # Ordered List Test This is some sample markdown used to test ordered lists. 1. Line item *one* of a sample markdown ordered list. 2. This is the *second* line item of a sample markdown ordered list. 3. And finally, the third line item of a sample markdown ordered list. """ I now encounter the unexpected behavior where the words that received the emphasis also have a paragraph attribute associated with them, as shown in the screenshot below. I can log the presentationIntent and confirm that in my console that there are now presentation intent components for listItem, orderedList and now a paragraph. [paragraph (id 5), listItem 1 (id 4), orderedList (id 3)] So now it appears that in addition to having to restore and insert the 1., 2. etc, to the line items, but now I also need to make sure I strip out the added paragraph intent that gets added to a piece of text has emphaisis within an orderedList line item? This doesn't seem to make sense to me, am I doing something wrong?
Topic: UI Frameworks SubTopic: UIKit
0
1
410
Jul ’24
Is it possible to use a list-style UICollectionView but have multiple columns?
I'm working on a UICollectionView that has a custom compositional layout with multiple columns. I wanted to add swipe actions to the cells (specifically, a delete action). I knew this was possible because of the existence of trailingSwipeActionsConfigurationProvider but I didn't realize that this is only for list layouts, created with UICollectionViewCompositionalLayout.list. But if I use a list layout, I don't think I have any opportunity to add multiple columns. Do I really have to choose between multiple columns and trailing swipe actions? Or is there some way to get both?
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
476
Jul ’24
Large Title Navigation Bar Problems with Two Views
As has been posted a number of times, the large title navigation bar only collapses on scrolling for the UIView listed first in an .xib or storyboard file. In my case, I have an enclosing view containing 2 Views, a TableView and a CollectionView in an .XIB file. This is connected to a UIKit class. Tapping a button switches between the two views. If the TableView is the first view listed, the navigationbar collapses with scrolling but with the CollectionView listed second, the large title navigation bar doesn't collapse with scrolling. Alternatively, if the CollectionView is the first view listed, the navigation bar collapses with scrolling but with the TableView listed second, the large title navigation bar doesn't collapse with scrolling. I have not been able to figure out a way to enable the collapsable large title navigation bar to work in such a scenario as mine for both views within a container view. Is there a way to do this? I have tested this capability through iOS 17.
2
0
1.2k
Jul ’24
Show animation images using UIImageView
We want to animate the images using animationImages propery of UIImageView in our app. There are 45 heif images with dimensions of 1668x2388. Below is the code i am using to animate images. let imageViewAnimation = UIImageView() imgViewAnimation.animationImages = images imgViewAnimation.animationDuration = 5.0 imgViewAnimation.animationRepeatCount = 1 imgViewAnimation.startAnimating() Timer.scheduledTimer(withTimeInterval: 5.0 + 0.5, repeats: false) { _ in DispatchQueue.main.async { self.showAlert() } } The issue i am facing is, it takes more than 5.0 seconds (animationDuration) to display all the images. Alert is shown before all the images are shown. We face this issue only for few sets of images. For some other sets, it is working fine. Is this issue due to heif images used, or due to memory and CPU load of using large number of images.
2
0
692
Jul ’24
scene(_:continue:) not invoked
Hi all, I recently migrated our app from AppDelegate to SceneDelegate in order to make it available on visionOS. So far it is working, but I have a problem with Universal links not being invoked. I implemented: func scene(_ scene: UIScene, continue userActivity: NSUserActivity) in my Scene Delegate, but it doesn't get invoked after the system opens the app. This only happens, if the app is running in the background. If the app is not running and is launched by the OS, I receive the URL as expected in: func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) If I also implement: func scene(_ scene: UIScene, willContinueUserActivityWithType userActivityType: String) it will be invoked by the OS, but after willContinueUserActivityWithType was called, neither: func scene(_ scene: UIScene, didFailToContinueUserActivityWithType userActivityType: String, error: any Error) nor: func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) are being invoked by the OS. I made a simple Barebones project with the same Bundle ID and the same Entitlements and there: func scene(_ scene: UIScene, continue userActivity: NSUserActivity) is being invoked as expected, upon tapping on the Universal Link in another app. What might be the difference between the two projects causing this behaviour? It is a rather big and old app, so it is difficult for me to compare the simple example project to the real project. Does anybody know, where I could start to debug? Many thanks in advance!
1
0
878
Jul ’24
UIDocumentViewController and multiple windows
I'm trying to migrate my document-based app to UIDocumentViewController so that it can take advantage of the new launch experience in iOS 18. Unfortunately, UIDocumentViewController closes the UIDocument when the document is set to nil or the controller is deallocated. This means you can't have the same document in more than one scene. Is there any way to prevent UIDocumentViewController from closing the document? -Steve
Topic: UI Frameworks SubTopic: UIKit
1
0
462
Jul ’24
Extremely long UITextView text causing performing issues
I have an extremely (et cetera ad infinitum) textview that is lagging when typing (presumably) because of the text. Not sure what textkit is doing under the hood but if I were building it from scratch I wouldn't need to do any calc when the user is typing. I could just would design it so each new line is like's it's own textfield so to speak. But clearly that isn't the case. Any suggestions / can someone at Apple on the textkit team reach out ? (I interviewed with someone from that team before so I know it exists lol)
Topic: UI Frameworks SubTopic: UIKit
0
0
337
Jul ’24
Mixing capabilities from different Pass Types
I'm looking into developing a Pass that drills down into other screens and would add buttons below a pass. I'm finding it hard to get any information on these capabilities. Does anyone have any resources that might help. Essentially, mixing features between different pass types (payment cards, generic passes, etc).
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
407
Jul ’24
Issue with 24-hour time format in UIDatePicker and possible workarounds
Dear Apple Support Team, I am currently developing a control in my app that uses UIDatePicker for time input. To ensure that the time display format is consistently in 24-hour notation regardless of the region, I have set the locale of UIDatePicker to ‘systemLocale’. However, while this worked as expected up to iPadOS15, displaying the time in 24-hour format, it has switched to a 12-hour format from iPadOS16 onwards. I am wondering if there have been any changes in the behavior of UIDatePicker’s locale between the updates from iPadOS15 to iPadOS16? Additionally, I would like to know if there are any workarounds to this issue that do not involve modifying the program. In other words, is there a way to revert back to the 24-hour format without changing the code? Any information you could provide on this issue would be greatly appreciated. Thank you for your assistance.
2
0
964
Jul ’24
Crash on TextField
A crash when Use UITextfield to display special characters "美҈̛̍̐̃͒̑́̌̆̾̒̿̒̚̚҈҉̵̶̸̷̷҇̒́̎͐͊̎̑̆́̓̽͂̊͋̑͛͑̈́̉̄̿́̏̽̎̓̋̓́̀̿͒͗͐̇҇͌̏͛͐̈́̑̀̏̏̋̏͑̊͋̈́̉̃̀̉͌̾̍͐͊̃́̉̍̈̎̒̊̉̚̕̚͠͝͠ 】". the system is iOS 16.3.1 and iOS 17.5.1 0 CoreFoundation ___exceptionPreprocess + 164 1 libobjc.A.dylib _objc_exception_throw + 60 2 Foundation _blockForLocation 3 UIFoundation -[NSTextLineFragment _defaultRenderingAttributesAtCharacterIndex:effectiveRange:] + 104 4 UIFoundation ___53-[NSTextLineFragment initWithAttributedString:range:]_block_invoke + 72 5 CoreText TLine::DrawGlyphsWithAttributeOverrides(CGContext*, __CFDictionary const* ( block_pointer)(long, CFRange*), void ( block_pointer)(CTLineDecorationType, void const*, bool, double, double, double, int, CGPoint, CFRange)) const + 424 6 UIFoundation __NSCoreTypesetterRenderLine + 368 7 UIFoundation -[NSTextLineFragment drawAtPoint:graphicsContext:] + 164 8 UIFoundation -[NSTextLineFragment drawAtPoint:inContext:] + 88 9 UIFoundation -[NSTextLayoutFragment drawAtPoint:inContext:] + 244 10 UIKitCore __UITextCanvasDrawWithFadedEdgesInContext + 256 11 UIKitCore -[_UITextLayoutFragmentView drawRect:] + 228 12 UIKitCore -[UIView(CALayerDelegate) drawLayer:inContext:] + 508 13 QuartzCore CABackingStoreUpdate + 252 14 QuartzCore ___ZN2CA5Layer8display_Ev_block_invoke + 64 15 QuartzCore -[CALayer _display] + 1636 16 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 416 17 QuartzCore CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 18 QuartzCore CA::Transaction::commit() + 648 19 QuartzCore CA::Transaction::flush_as_runloop_observer(bool) + 88 20 UIKitCore __UIApplicationFlushCATransaction + 52 21 UIKitCore __UIUpdateSequenceRun + 84 22 UIKitCore _schedulerStepScheduledMainSection + 172 23 UIKitCore _runloopSourceCallback + 92 24 CoreFoundation _CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 25 CoreFoundation ___CFRunLoopDoSource0 + 176 26 CoreFoundation ___CFRunLoopDoSources0 + 244 27 CoreFoundation ___CFRunLoopRun + 828 28 CoreFoundation _CFRunLoopRunSpecific + 608 29 GraphicsServices _GSEventRunModal + 164 30 UIKitCore -[UIApplication _run] + 888 31 UIKitCore _UIApplicationMain + 340 32 UIKitCore _keypath_get_selector_hoverStyle + 11024
Topic: UI Frameworks SubTopic: UIKit
1
0
414
Jul ’24