2021 EssentialsSwiftUI & UI Frameworks
WWDC21 · 27 min · Essentials / SwiftUI & UI Frameworks
What’s new in UIKit
Discover the latest updates and improvements to UIKit and learn how to build better iPadOS, iOS, and Mac Catalyst apps. We’ll take you through UI refinements, productivity updates, and API enhancements, and help you explore performance improvements and security & privacy features.
Watch at developer.apple.com ↗Code shown on screen · 8 snippets
Building an "Open in New Window" action
// Building an "Open in New Window" action
let newSceneAction = UIWindowScene.ActivationAction({ _ in
// Create the user activity that represents the new scene content
let userActivity = NSUserActivity(activityType: "com.myapp.detailscene")
// Return the activation configuration
return UIWindowScene.ActivationConfiguration(userActivity: userActivity)
}) UIMenuBuilder
class AppDelegate: UIResponder, UIApplicationDelegate {
override func buildMenu(with builder: UIMenuBuilder) {
// Use the builder to modify the main menu...
}
} UIBarAppearance
let appearance = UITabBarAppearance()
appearance.backgroundEffect = nil
appearance.backgroundColor = .blue
tabBar.scrollEdgeAppearance = appearance
let scrollView = ... // Content scroll view in your app
viewController.setContentScrollView(scrollView, for: .bottom) Creating a button with UIButton.Configuration
// Creating a button with UIButton.Configuration
var config = UIButton.Configuration.tinted()
config.title = "Add to Cart"
config.image = UIImage(systemName: "cart.badge.plus")
config.imagePlacement = .trailing
config.buttonSize = .large
config.cornerStyle = .capsule
self.addToCartButton = UIButton(configuration: config) Using a hierarchical color symbol
// Using a hierarchical color symbol
let configuration = UIImage.SymbolConfiguration(
hierarchicalColor: UIColor.systemOrange
)
let image = UIImage(
systemName: "sun.max.circle.fill",
withConfiguration: configuration
) New UICollectionViewCell.configurationUpdateHandler closures
// New UICollectionViewCell.configurationUpdateHandler closures
let cell: UICollectionViewCell = ...
cell.configurationUpdateHandler = { cell, state in
var content = UIListContentConfiguration.cell().updated(for: state)
content.text = "Hello world!"
if state.isDisabled {
content.textProperties.color = .systemGray
}
cell.contentConfiguration = content
} Image display preparation
// Image display preparation
if let image = UIImage(contentsOfFile: pathToImage) {
// Prepare the image for display asynchronously.
Task {
let preparedImage = await image.byPreparingForDisplay()
imageView.image = preparedImage
}
} Image thumbnailing
// Image thumbnailing
if let bigImage = UIImage(contentsOfFile: pathToBigImage) {
// Prepare the thumbnail asynchronously.
Task {
let smallImage = await bigImage.byPreparingThumbnail(ofSize: smallSize)
imageView.image = smallImage
}
} Resources
Related sessions
-
23 min -
27 min -
24 min -
36 min -
41 min -
20 min -
34 min -
13 min -
15 min -
23 min -
20 min -
22 min