how do I create a new text style?

Asked on 2024-07-30

1 search

To create a new text style, you can follow these steps based on the information provided in the WWDC sessions:

  1. Using UIKit:

    • Set the adjustsFontForContentSizeCategory property on a UILabel to true so that the label automatically updates its font when the system text size changes.
    • Set the font by using preferredFont(forTextStyle:) with your desired style.
    • Consider setting the numberOfLines on the label to zero to allow the text to take as many lines as it needs and avoid truncations.

    For more details, you can refer to the session Get started with Dynamic Type.

  2. Using SwiftUI:

    • Use the font modifier with a built-in text style. For example, you can pass the title parameter to select the title style.

    For more details, you can refer to the session Get started with Dynamic Type.

  3. Text Highlighting:

    • Use the new textHighlightStyle for the range of text that should be highlighted and textHighlightColorScheme for the color used to render the highlight. There are predefined color schemes in addition to the default, which uses the tint color.

    For more details, you can refer to the session What’s new in UIKit.

  4. Attributed Strings:

    • You can add a color attribute to an attributed string to highlight parts of the text.

    For more details, you can refer to the session Build multilingual-ready apps.

Relevant Sessions

  1. Get started with Dynamic Type
  2. What’s new in UIKit
  3. Build multilingual-ready apps

If you need more specific details or have another question, feel free to ask!