• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Obscuring
2
3When needed, you can obscure content of a component.
4
5>  **NOTE**
6>
7> The APIs of this module are supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version.
8
9## obscured
10
11obscured(reasons: Array<ObscuredReasons>)
12
13Sets how the component content is obscured.
14
15**Atomic service API**: This API can be used in atomic services since API version 11.
16
17**System capability**: SystemCapability.ArkUI.ArkUI.Full
18
19**Parameters**
20
21
22| Name| Type                                    | Mandatory                                  | Description                                 |
23| -----| ------------------------------------------ | ------------------------------------ | ------------------------------------ |
24| reasons | Array<[ObscuredReasons](ts-appendix-enums.md#obscuredreasons10)> | Yes| How the component content is obscured.<br>Default value: **[]**<br>This API only works for the [Image](ts-basic-components-image.md)<!--Del-->, [Formcomponent](ts-basic-components-formcomponent-sys.md)<sup>12+</sup>,<!--DelEnd--> and [Text](ts-basic-components-text.md) components.<br>**NOTE**<br>To obscure an image when it is being loaded, you must set the width and height of the **Image** component.<br>Obscuring is not available for **Text** components that have child components or have any [styled string](ts-universal-styled-string.md#styled-string) configured.|
25
26## Example
27
28This example demonstrates how to obscure the content of **Text** and **Image** components using the **obscured** API.
29
30```ts
31// xxx.ets
32@Entry
33@Component
34struct ObscuredExample {
35  build() {
36    Row() {
37      Column() {
38        Text('Text not set obscured attribute').fontSize(10).fontColor(Color.Black)
39        Text('This is an example for text obscured attribute.')
40          .fontSize(30)
41          .width('600px')
42          .fontColor(Color.Black)
43          .border({ width: 1 })
44        Text('Image not set obscured attribute').fontSize(10).fontColor(Color.Black)
45        Image($r('app.media.icon'))
46          .width('200px')
47          .height('200px')
48        Text('Text set obscured attribute').fontSize(10).fontColor(Color.Black)
49        Text('This is an example for text obscured attribute.')
50          .fontSize(30)
51          .width('600px')
52          .fontColor(Color.Black)
53          .border({ width: 1 })
54          .obscured([ObscuredReasons.PLACEHOLDER])
55        Text('Image set obscured attribute').fontSize(10).fontColor(Color.Black)
56        Image($r('app.media.icon'))
57          .width('200px')
58          .height('200px')
59          .obscured([ObscuredReasons.PLACEHOLDER])
60      }
61      .width('100%')
62    }
63    .height('100%')
64  }
65}
66```
67
68![obscured](figures/obscured.png)
69