ts-universal-attributes-overlay.md 1.3 KB
Newer Older
Z
zengyawen 已提交
1
# Overlay
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
You can set overlay text for a component.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5 6 7
>  **NOTE**
>
> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10
## Attributes

E
ester.zhou 已提交
11 12 13
| Name      | Type                         | Description                      |
| ------- | ----------------------------- | ------------------------- |
| overlay | value: string,<br>options?: {<br>align?: [Alignment](ts-appendix-enums.md#alignment), <br>offset?: {<br>  x?: number,<br>  y?: number<br> }<br>} | Overlay added to the component. The overlay has the same layout as the component.<br>Default value:<br>{<br>align: Alignment.Center,<br>offset: {0, 0}<br>} |
Z
zengyawen 已提交
14 15 16


## Example
Z
zengyawen 已提交
17

E
ester.zhou 已提交
18 19
```ts
// xxx.ets
Z
zengyawen 已提交
20 21 22 23 24 25 26 27 28 29 30
@Entry
@Component
struct OverlayExample {
  build() {
    Column() {
      Column() {
        Text('floating layer')
          .fontSize(12).fontColor(0xCCCCCC).maxLines(1)
        Column() {
          Image($r('app.media.img'))
            .width(240).height(240)
Z
zengyawen 已提交
31
            .overlay("Winter is a beautiful season, especially when it snows.", { align: Alignment.Bottom, offset: { x: 0, y: -15 } })
Z
zengyawen 已提交
32 33 34 35 36 37 38
        }.border({ color: Color.Black, width: 2 })
      }.width('100%')
    }.padding({ top: 20 })
  }
}
```

Z
zengyawen 已提交
39
![en-us_image_0000001212058472](figures/en-us_image_0000001212058472.png)