title: WWDC 2022/What’s new in UIKit Date: [[Jun 7th, 2022]] Conference: [[WWDC 2022]] Speaker(s): Tags: [[Talks]] Slides: Video: - ## Productivity on iPad - ### Navigation Bars - Styles - Navigator - Browser **new** - Editor **new** - Supports editable toolbars on iPad and Mac - Overflow menu - New Title Menu - Duplicate - Move - Rename - Export - Print - [[Mac Catalyst]] - ### Text - Find and replace - Find interaction - `UITextView`, `WKWebView`, `PDFView` - Edit menu - Alterante presentations depending on input - Customizable brides nicely to Catalyst - New `EditMenuInteraction` API - Replaces `UIMenuController` - see: [[WWDC 2022: Adopt desktop class editing interactions]] - ### Materials in Sidebar - Vibrant sidebar by default - ## `UICalendarView` - `UICalendarView` - Different types of selection behaviors - Disable individual dates from selection - **Annotate dates with decorations** - Better more correct representation of the data model - `NSCalendar.currentCalendar` may not be Gregorian - Be explicit about which calendar to use - **Configuring a calendar view with multi-date selection** - ```swift // Configuring a calendar view with multi-date selection let calendarView = UICalendarView() calendarView.delegate = self calendarView.calendar = Calendar(identifier: .gregorian) view.addSubview(calendarView) let multiDateSelection = UICalendarSelectionMultiDate(delegate: self) multiDateSelection.selectedDates = myDatabase.selectedDates() calendarView.selectionBehavior = multiDateSelection func multiDateSelection( _ selection: UICalendarSelectionMultiDate, canSelectDate dateComponents: DateComponents ) -> Bool { return myDatabase.hasAvailabilities(for: dateComponents) } ``` - **Configuring Decorations** - ```swift // Configuring Decorations func calendarView( _ calendarView: UICalendarView, decorationFor dateComponents: DateComponents ) -> UICalendarView.Decoration? { switch myDatabase.eventType(on: dateComponents) { case .none: return nil case .busy: return .default() case .travel: return .image(airplaneImage, color: .systemOrange) case .party: return .customView { MyPartyEmojiLabel() } } } ``` - ## `UIPageControl` - Different images depending on seletion state - Control layout direction - ```swift // Vertical page control with custom indicators pageControl.direction = .topToBottom pageControl.preferredIndicatorImage = UIImage(systemNamed: "square") pageControl.preferredCurrentIndicatorImage = UIImage(systemNamed: "square.fill") ``` - ## `UIPasteControl` - System will now alert for Pasteboard access - Use `UIPasteControl` instead - ## Sheet Detents - ```swift // Create a custom detent sheet.detents = [ .large(), .custom { context in 0.3 * context.maximumDetentValue } ] ``` - Assigning Identifiers for custom detents - ```swift // Define a custom identifier extension UISheetPresentationController.Detent.Identifier { static let small = UISheetPresentationController.Detent.Identifier("small") } // Assign identifier to custom detent sheet.detents = [ .large(), .custom (identifier: .small) { context in 0.3 * context.maximumDetentValue } ] // Disable dimming above the custom detent sheet.largestUndimmedDetentIdentifier = .small ``` - see: [[WWDC 2022/Customize and resize sheets in UIKit]] - ## [[SF Symbols]] - Default rendering mode - May not always be monochrome in iOS 16 (some now default to hierarchical) - Explicitly request - `.preferringMonochrome()` if you need it - Variable symbols - Symbols reflecting a value from 0 to 1 - Example: `speaker.3.wave.fill` - Now supports variable rendering - `UIImage(systemName: "wifi", variableValue: 0.6)` - see: [[WWDC 2022/Adopt variable color in SF Symbols]] see: [[WWDC 2022/What’s New in SF Symbols 4]] - ## Swift Concurrency and Sendable - `UIColor` and `UIImage` are now `Sendable` - see: [[WWDC 2022/Eliminate data races using Swift concurrency]] see: [[WWDC 2022/Visualize and optimize Swift concurrency]] - ## Stage manager - Automatic support as long as you’re not relying on `UIScreen.main` - ## Self-resizing cells - Enabled by default for `UICollectionView` and `UITableView` - Cells automatically resized when their content changes - `UICollectionView.selfSizingInvalidation` id: 629fa603-0322-459b-9c90-78325069633e - Automatic invalidation when using `UIListContentConfiguration` - For other cases use `invalidateIntrinsicContentSize` on the cell or content view - Wrap in `performWithoutAnimation` to resize without animation - You can opt-into invalidation including constraints via `UICollectionView.selfSizingInvalidation` - ## UIHostingConfiguration - Cells that host Swift UI views - ```swift cell.contentConfiguration = UIHostingConfiguration { VStack { Image(systemName: "wand.and.stars") .font(.title) Text("Like magic!") .font(.title2).bold() } .foregroundStyle(Color.purple) } ``` - see: [[WWDC 2022/Using SwiftUI with UIKit]] - ## UIDevice deperecations - `UIDevice.name` no longer reports the custom name - Settings UIDevice.orientation is no longer supported - ## Next Steps - Compile your app for iOS 16 - Check out new system features - Adopt new UIKit APIs