Object

ImageFill

The object for adding an image background fill to a component.

Properties

URL
uri
(Required)

The URL of the image file to use for filling the component.

Image URLs can begin with http://, https://, or bundle://. If the image URL begins with bundle://, the referenced image file must be in the same directory as the document.

Image filenames should be properly encoded as URLs. For example, spaces in a URL should be encoded as %20. See Using Images, Videos, and Audio Files.

Version 1.0

fillMode
string

Indicates how the image fill should be displayed. Valid values:

  • fit: Scales the image by aspect ratio to fit the component.

  • cover:(default): Scales the image by aspect ratio to completely fill the component.

Version 1.0

horizontalAlignment
string

Sets the horizontal alignment of the image fill within its component. Valid values:

  • left: Aligns the left edge of the fill with the left edge of the component.

  • center (default): Aligns the horizontal center of the fill with the center of the component.

  • right: Aligns the right edge of the fill with the right edge of the component.

You can use fillMode with horizontalAlignment to achieve the effect you want. For example, set fillMode to fit and horizontalAlignment to left to fit the image based on its aspect ratio and also align the left edge of the fill with the left edge of the component. Or set fillMode to cover and horizontalAlignment to right to scale the image horizontally and also align the right edge of the fill with the right edge of the component.

Version 1.0

type
string
(Required)

The type of fill to apply. This property should always be set to image.

Version 1.0

verticalAlignment
string

Sets the vertical alignment of the image fill within its component. Valid values:

  • top: Aligns the top of the fill with the top edge of the component.

  • center (default): Aligns the vertical center of the fill with the center of the component.

  • bottom: Aligns the bottom of the fill with the bottom edge of the component.

You can use fillMode with verticalAlignment to achieve the effect you want. For example, set fillMode to fit and verticalAlignment to top to fit the image based on its aspect ratio and also align the top of the fill with the top edge of the component. Or set fillMode to cover and verticalAlignment to top to scale the image vertically and also align the top of the fill with the top edge of the component.

Version 1.0

attachment
string

Discussion

Use the ImageFill object to fill a component with a background image.

To avoid having the image cut off on different devices, calculate the minimum height needed for the image. For example, the following shows the minimum height calculation of a full display based on an image with dimensions 2184 x 1456 pixels:

100 * (height / width) + “cw”

100 * (1456 / 2184) + “cw”

“66.67cw”

For more information about the use of cw, see Specifying Measurements for Components.

This object can be used in ComponentStyle.

Create a Layered Effect with a Background

You can create a layered or collage effect by using a background image with a header container component. Create a header that contains the other components you want in the top section of your article, such as the title and intro, and then apply a background image to the header component. All content in the header component appears in front of the background, creating a layered effect.

Set a Fixed Image Fill

One of the most captivating effects in Apple News Format is the fixed image fill. With this background, the image stays still as the user scrolls, with the rest of the content in the article seeming to move independently of the image. As long as any part of the component containing the image is visible in the viewport, the image remains still.

To create this effect, use a ComponentStyle object with image as the fill type, and then give the attachment property the value of fixed.

Example

{ "components": [ { "role": "container", "style": "exampleComponentStyle", "layout": { "minimumHeight": 150 }, "components": [ { "role": "title", "text": "Drought", "anchor": { "targetAnchorPosition": "center" }, "textStyle": { "fontSize": 60 } } ] } ], "componentStyles": { "exampleComponentStyle": { "fill": { "type": "image", "URL": "bundle://image.jpg", "fillMode": "cover", "verticalAlignment": "top" } } }}

Relationships

Inherits From

See Also

Backgrounds for Components

Applying a Background to a Component

Change the appearance of the backgrounds in your article.

object RepeatableImageFill

The object for adding a background image that can be repeated.

object VideoFill

The object for adding a video background fill to a component.

object LinearGradientFill

The object for displaying a linear gradient as a component background.

object GradientFill

The properties shared by all gradient fill types.

object Fill

The object for setting a fill type and attachment for a component’s background fill.

object ColorStop

The object for specifying the color and location for a color stop in a gradient.