UITraitCollection

Generated on 8/5/2024

1 search

The UITraitCollection in UIKit has received several updates in iOS 18, making it easier to use traits and handle changes. Here are some key points:

  1. Automatic Trait Tracking:

    • UIKit now supports automatic trait tracking inside common view and view controller update methods such as layoutSubviews and drawRect. When these methods are called, UIKit records which traits are accessed. If any of those traits change, UIKit automatically performs the associated invalidation for that method, such as calling setNeedsLayout or setNeedsDisplay.
    • This feature eliminates the need for manual trait change registration, improving performance by only creating necessary trait dependencies.

    For more details, you can refer to the session What’s new in UIKit (06:03).

  2. List Environment Trait:

    • UI collection view list sections and UITableViews now have the listEnvironment trait set. This trait describes the style of the list that the view is in, ensuring that cells are styled appropriately.
    • UIListContentConfiguration and UIBackgroundConfiguration now take advantage of this new trait, adjusting their properties to match the list environment from the configuration state’s trait collection.

    For more details, you can refer to the session What’s new in UIKit (07:54).

These enhancements streamline the use of traits in UIKit, making it more efficient and reducing the need for manual updates.

What’s new in UIKit

What’s new in UIKit

Explore everything new in UIKit, including tab and document launch experiences, transitions, and text and input changes. We’ll also discuss better-than-ever interoperability between UIKit and SwiftUI animations and gestures, as well as general improvements throughout UIKit.

A Swift Tour: Explore Swift’s features and design

A Swift Tour: Explore Swift’s features and design

Learn the essential features and design philosophy of the Swift programming language. We’ll explore how to model data, handle errors, use protocols, write concurrent code, and more while building up a Swift package that has a library, an HTTP server, and a command line client. Whether you’re just beginning your Swift journey or have been with us from the start, this talk will help you get the most out of the language.

Enhance your UI animations and transitions

Enhance your UI animations and transitions

Explore how to adopt the zoom transition in navigation and presentations to increase the sense of continuity in your app, and learn how to animate UIKit views with SwiftUI animations to make it easier to build animations that feel continuous.

SwiftUI essentials

SwiftUI essentials

Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.