12/25/2023 0 Comments Uiimage systemnamePrivate lazy var likeButton = UIButton(type. UIImage has a new initializer, UIImage(systemName:) that takes a string and returns one of over 1500 different system icons. title1) let image UIImage(systemName: 'location. That can now be easily done, without having to implement any complex UIButton subclasses, using a set of static factory methods: extension UIButton. let configuration UIImage.SymbolConfiguration(textStyle. Not only does that let us base our configurations on system ones, we can also then continue to compose and combine those custom configurations as well, enabling us to build up a “hierarchy” of increasingly specific configurations.įor example, we might want to extract parts of the above likeButton configuration into a more general-purpose action configuration, and then implement our like variant as a specialization of that more generic configuration. That’s one of my favorite aspects of this new API - since it’s value type-based, it’s incredibly composable. Use SF Symbols to find symbols and their corresponding names. Instead, we’re deriving our custom configuration from the built-in filled one. This initializer creates an image using a system-provided symbol. Note how we didn’t start by creating a brand new UIButton.Configuration value. Top: 10, leading: 8, bottom: 10, trailing: 8 image = UIImage(systemName: "hand.thumbsup")Ĭonfig. So, this year, Apple is introducing a really nice (and quite powerful) new system for configuring UIKit-based buttons, which enables us to easily describe configurations that can then be applied to any UIButton instance: var config = UIButton. The fact that many of UIKit’s core classes, including UIButton, have stood the test of time so well is really a great achievement for the engineers who originally designed those initial public APIs.īut, times have changed, and with the introduction of frameworks like SwiftUI many developers are now expecting to be able to work at a slightly more higher level, using more declarative and descriptive APIs. To summarize, the custom cell will create and assign a content. It has only 1 task generate a properly configured content configuration object based on the state (selected, highlighted, disabled, etc.) of the cell and then assign the configuration to itself. Obviously, there were no SFSymbols back when the iPhone SDK was first released, and there was no Swift either for that matter, but you get my point. A custom cell of a UICollectionView list is a subclass of UICollectionViewListCell. For example, the way we configure the title, image, and background color of a button looks more or less the same today as it did back in 2008: let likeButton = UIButton(type. Let’s take it for a quick spin! From imperative to descriptiveĪlthough the default appearance of UIButton has changed quite a lot since its original introduction in the very first public release of the iOS SDK (or iPhone SDK as it was known as back then), many of its core configuration APIs have remained mostly unchanged during all of those years. In fact, one of UIKit’s most fundamental classes, UIButton, is getting a brand new system for configuring many aspects of a button’s appearance and behavior. SwiftUI isn’t the only UI framework that has received significant new APIs and updates during this year’s WWDC.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |