ImageFill
The object for adding an image background fill to a component.
Declaration
object ImageFillProperties
| Name | Type | Description |
|---|---|---|
URL Required | uri | The URL of the image file to use for filling the component. Image URLs can begin with Encode image filenames as URLs. |
attachment | string | A string that indicates how the fill behaves when a person scrolls. Valid values:
|
fillMode | string | Indicates how Apple News displays the image fill. Valid values:
|
horizontalAlignment | string | Sets the horizontal alignment of the image fill within its component. Valid values:
You can use |
type Required | string | The type of fill to apply. Always set this property to |
verticalAlignment | string | Sets the vertical alignment of the image fill within its component. Valid values:
You can use |
Mentioned in
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.
You can use this object 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 a person 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.
[Image]
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"
}
}
}
}