![]() If you do this, then all the UILabel instances show up in bold font. Life is good so far, but what if you want to specify two different variations of the same font, like bold font? You would think you can just add another extension property substituteBoldFontName and call it like this, right? UILabel.appearance().substituteFontName = fontNameUILabel.appearance().substituteBoldFontName = boldFontName ? But you want to use bold font as well, don’t you? ![]() You can call it in AppDelegate.application(:didFinishLaunching.) UILabel.appearance().substituteFontName = "Gills Sans"Īnd voilà, all UILabel will be in the “Gills Sans” font with appropriate sizes. When you create UIView extension and declare a property with modifier, you can set that property through UIAppearance.įor example, if you declare a UILabel extension property substituteFontName like this: ![]() This short article explains how you can do that with just several lines of code. Or your app wants to cover another language, and you want to use another font for the language because it would look better. Since UIFont always needs the size information to be initialized, there is no standard way in UIKit to just change the typeface without affecting the size.īut, don’t you want to change the font typeface without hunting down all the Swift files and Interface Builder files? Imagine you have an app with tens of screens and the product owner decides to change the font for the entire app. I don’t think any app would want to have only 14pt fonts throughout the app. However, if you apply the same approach to the font like this: UILabel.appearance().font = UIFont(named: "Gills Sans", size: 14)Īll the UILabel instances will indeed have “Gills Sans”, but with 14pt size as well. For example, you can set a consistent background color of the navigation bar with just one line : UINavigationBar.appearance().barTntColor = UIColor.blue In iOS, there is a mechanism called UIAppearance to define an app’s global configuration. In this article, you'll learn how to create a unified custom look throughout your app with these simple tricks.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |