2020 SwiftUI & UI Frameworks
WWDC20 · 30 min · SwiftUI & UI Frameworks
Modern cell configuration
Discover new techniques for configuring collection view and table view cells to quickly build dynamic interfaces in your app. Explore configuration types you can use to easily populate cells with content and apply common styles. Take advantage of powerful APIs to customize the appearance of cells for different states. Find out about patterns and best practices that simplify your code, eliminate bugs, and improve performance.
Watch at developer.apple.com ↗Code shown on screen · 6 snippets
Configuring a UITableViewCell
cell.imageView?.image = UIImage(systemName: "star")
cell.textLabel?.text = "Hello WWDC!" Configuring a UITableViewCell Using a Content Configuration
var content = cell.defaultContentConfiguration()
content.image = UIImage(systemName: "star")
content.text = "Hello WWDC!"
cell.contentConfiguration = content Updating Configurations
let updatedConfiguration = configuration.updated(for: state) Customizing Appearance for Different States
override func updateConfiguration(using state: UICellConfigurationState) {
var content = self.defaultContentConfiguration().updated(for: state)
content.image = self.item.icon
content.text = self.item.title
if state.isHighlighted || state.isSelected {
content.imageProperties.tintColor = .white
content.textProperties.color = .white
}
self.contentConfiguration = content
} Default Configurations
var background = UIBackgroundConfiguration.listSidebarCell()
var content = UIListContentConfiguration.sidebarCell() Creating a List Content View
var content = UIListContentConfiguration.cell()
// Set up the content configuration as desired...
let contentView = UIListContentView(configuration: content) Resources
Related sessions
-
26 min -
11 min -
20 min -
17 min -
12 min -
10 min -
24 min