ui traits
Generated on 8/5/2024
1 search
The trait system in UIKit has seen significant improvements in iOS 18, making it easier to use and handle changes. Here are some key updates:
-
Automatic Trait Tracking:
- UIKit now supports automatic trait tracking inside common view and view controller update methods such as
layoutSubviews
anddrawRect
. 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 assetNeedsLayout
orsetNeedsDisplay
. - This feature eliminates the need for manual trait change registration, enhancing performance by only creating necessary trait dependencies. For more details, you can refer to the What’s new in UIKit session.
- UIKit now supports automatic trait tracking inside common view and view controller update methods such as
-
List Environment Trait:
- UI collection view list sections and UITableViews now have the list environment trait set. This trait describes the style of the list that the view is in, ensuring that cells are styled appropriately in any given list.
- UI list content configuration and UI background configuration now take advantage of this new trait, adjusting their properties to match the list environment from the configuration state's trait collection. This simplifies the cell configuration code, as it no longer needs to know the style of the list. For more details, you can refer to the What’s new in UIKit session.
-
Writing Tools Input Traits:
- New tech input traits API allows customization of writing tools behavior to better suit your app. You can set the writing tool's behavior to limited for a panel experience or none to opt out completely for a text view. This is particularly useful for apps with custom text views other than
UITextView
. For more details, you can refer to the Get started with Writing Tools session.
- New tech input traits API allows customization of writing tools behavior to better suit your app. You can set the writing tool's behavior to limited for a panel experience or none to opt out completely for a text view. This is particularly useful for apps with custom text views other than
Relevant Sessions
These updates make it easier to manage and utilize traits in your iOS applications, enhancing both performance and ease of use.
Get started with Writing Tools
Learn how Writing Tools help users proofread, rewrite, and transform text in your app. Get the details on how Writing Tools interact with your app so users can refine what they have written in any text view. Understand how text is retrieved and processed, and how to support Writing Tools in custom text views.
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.
Meet Swift Testing
Introducing Swift Testing: a new package for testing your code using Swift. Explore the building blocks of its powerful new API, discover how it can be applied in common testing workflows, and learn how it relates to XCTest and open source Swift.