Contents

ConditionalTextStyle

The object for defining conditional properties for a text style, and when the conditional properties are in effect.

Declaration

object ConditionalTextStyle

Properties

NameTypeDescription
conditions Required(Condition | [Condition])

An instance or array of conditions that, when met, cause the conditional text style properties to take effect.

backgroundColor(Color | string("none"))

The background color for text lines. This value defaults to transparent.

To remove a previously set condition, use none.

fontFamily(string | string("system"))

The font family to use for text rendering; for example, Gill Sans. Using a combination of fontFamily, fontWeight, and fontStyle, you can define the appearance of the text. Apple News automatically selects the appropriate font variant from the available variants in that family. See Applying Apple News Format Fonts.

In iOS 13, iPadOS 13, and macOS 10.15 and later, you can use the value system to show text in the default font used by the operating system.

fontNamestring

The font name to use to refer to an explicit font variant’s PostScript name, such as GillSans-Bold. Alternatively, you can use a combination of fontFamily, fontWeight, and fontStyle to have Apple News automatically select the appropriate variant depending on the text formatting used.

See Applying Apple News Format Fonts.

fontSizeinteger

The size of the font, in points. By default, the font size is inherited from a parent component or a default style. As a best practice, try not to go below 16 points for body text. Apple News may automatically resize the fontSize for different device sizes or for iOS and iPadOS devices with Larger Accessibility Sizes enabled.

fontStylestring

The font style to apply for the selected font.

Valid values:

  • normal. Selects from the font family a font that Apple News defines as normal.

  • italic. Selects from the font family a font that Apple News defines as italic. If the family doesn’t contain an italic font variant, but contains an oblique variant, Apple News selects oblique instead.

  • oblique. Selects from the font family a font that Apple News defines as oblique. If the family doesn’t contain an oblique font variant, but contains an italic variant, Apple News selects italic instead.

fontWeight(integer | string)

The font weight to apply for the selected font. In addition to explicit weights (named or numerical), lighter and bolder are available, to set text in a lighter or bolder font as compared to the surrounding text.

If Apple News can’t find a font variant with the given specifications in the provided font family, it selects an alternative with the closest match. If Apple News doesn’t find a bold/bolder font, it doesn’t create a faux-bold alternative, and instead uses the closest match. Similarly, if Apple News can’t find an italic or oblique font variant, it won’t slant text or make it appear italicized.

Valid values:

  • thin or 100. Thin or hairline weight.

  • extra-light, ultra-light, or 200. Extra-light or ultra-light weight.

  • light or 300. Light weight.

  • regular, normal, book, roman, or 400. Regular weight. This is the default if no weight is defined or inherited.

  • medium or 500. Medium weight.

  • semi-bold, demi-bold, or 600. Semi-bold or demi-bold weight.

  • bold or 700. Bold weight. This is the default when using <strong> or <b> tags in HTML with default fontWeight.

  • extra-bold, ultra-bold, or 800. Extra-bold or ultra-bold weight.

  • black, heavy, or 900. Black or heavy weight.

  • lighter. A weight lighter than its surrounding text. When you make the surrounding text bold, a value of lighter makes it medium.

  • bolder. A weight heavier than its surrounding text. When you make surrounding text light, a value of bolder makes it regular.

fontWidthstring

The font width for the selected font (known in CSS as font-stretch). This value defines the width characteristics of a font variant between normal, condensed, and expanded. Some font families are categorized by width (for example, Avenir Next and Avenir Next Condensed), so make sure that the font family you select supports the specified font width.

Valid values:

  • ultra-condensed. The most condensed variant.

  • extra-condensed. A very condensed variant.

  • condensed. A condensed variant.

  • semi-condensed. A semi-condensed variant.

  • normal (default). The font variant classified as normal.

  • semi-expanded. A semi-expanded variant.

  • expanded. An expanded variant.

  • extra-expanded. A very expanded variant.

  • ultra-expanded. The most expanded variant.

orderedListItems(ListItemStyle | string("none"))

An object for use with text components with HTML markup. You can create text styles containing an orderedListItems definition to configure how to display list items inside <ol> tags.

To remove a previously set condition, use none.

strikethrough(TextDecoration | boolean)

The text strikethrough. Set strikethrough to true to use the text color inherited from the textColor property as the strikethrough color, or provide a text decoration definition with a different color. By default, Apple News omits strikethrough (false).

stroke(TextStrokeStyle | string("none"))

The stroke style for the text outline. By default, Apple News omits stroke.

To remove a previously set condition, use none.

textColorColor

The text color.

textShadow(TextShadow | string("none"))

The text shadow for this style.

To remove a previously set condition, use none.

textTransformstring

The transform to apply to the text.

Valid values:

  • uppercase

  • lowercase

  • capitalize. Capitalizes the first letter of all words in the string.

  • smallcaps. Capitalizes the lowercase letters as short capital letters.

  • none (default)

trackingnumber

The amount of tracking (spacing between characters) in text, as a percentage of the font size. The actual spacing between letters is determined by combining information from the font and font size.

Example: Set tracking to 0.5 to make the distance between characters increase by 50% of the fontSize. With a font size of 10, the additional space between characters is 5 points.

underline(TextDecoration | boolean)

The text underlining. You can use this style for links. Set underline to true to use the text color as the underline color, or provide a text decoration with a different color. By default, Apple News omits underline (false).

unorderedListItems(ListItemStyle | string("none"))

An object for use with text components with HTML markup. You can create text styles containing an unorderedListItems definition to configure how to display list items inside <ul> tags.

To remove a previously set condition, use none.

verticalAlignmentstring

The vertical alignment of the text. You can use this property for superscripts and subscripts.

Overrides values specified in parent text styles.

Default value: baseline when unspecified, or the value specified in a TextStyle object applied to the same range.

The values superscript and subscript also adjust the font size to two-thirds of the size defined for that character range.

Mentioned in

Discussion

Use the ConditionalTextStyle object to define an array of conditional text style properties and the conditions under which to apply them. When a condition is met, the value of a property in ConditionalTextStyle overrides the value of the same property if defined in the parent TextStyle object. See TextStyle.

Example

{
  "components": [
    {
      "role": "body",
      "text": "Lorem ipsum dolor sit amet, <span data-anf-textstyle='exampleTextStyle'>consectetur adipiscing elit.</span>",
      "format": "html"
    }
  ],
  "textStyles": {
    "exampleTextStyle": {
      "textColor": "#FF0000",
      "conditional": [
        {
          "underline": true,
          "textColor": "#000",
          "conditions": [
            {
              "minContentSizeCategory": "XXXL"
            }
          ]
        }
      ]
    }
  }
}

See Also

Conditional Design Elements