• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 隐私遮罩
2
3用于对组件内容进行隐私遮罩处理。
4
5>  **说明:**
6>
7> 从API Version 10开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8
9## obscured
10
11obscured(reasons: Array<ObscuredReasons>)
12
13设置组件内容的遮罩类型。
14
15**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
16
17**系统能力:** SystemCapability.ArkUI.ArkUI.Full
18
19**参数:**
20
21
22| 参数名 | 类型                                     | 必填                                   | 描述                                  |
23| -----| ------------------------------------------ | ------------------------------------ | ------------------------------------ |
24| reasons | Array<[ObscuredReasons](ts-appendix-enums.md#obscuredreasons10)> | 是 | 设置组件内容的遮罩类型。<br>默认值:[]<br/>该接口支持在ArkTS卡片中使用。<br/>仅支持[Image](ts-basic-components-image.md)组件、[Text](ts-basic-components-text.md)组件<!--Del-->和[Formcompnent](ts-basic-components-formcomponent-sys.md)组件<sup>12+</sup><!--DelEnd-->的隐私遮罩处理。<br/>**说明:**<br/>如需在图片加载过程中显示隐私遮罩,需要设置Image组件的宽度和高度。<br/>Text组件设置子组件或设置[属性字符串](ts-universal-styled-string.md#属性字符串)时,不支持隐私遮罩。 |
25
26## 示例
27
28```ts
29// xxx.ets
30@Entry
31@Component
32struct ObscuredExample {
33  build() {
34    Row() {
35      Column() {
36        Text('Text not set obscured attribute').fontSize(10).fontColor(Color.Black)
37        Text('This is an example for text obscured attribute.')
38          .fontSize(30)
39          .width('600px')
40          .fontColor(Color.Black)
41          .border({ width: 1 })
42        Text('Image not set obscured attribute').fontSize(10).fontColor(Color.Black)
43        Image($r('app.media.icon'))
44          .width('200px')
45          .height('200px')
46        Text('Text set obscured attribute').fontSize(10).fontColor(Color.Black)
47        Text('This is an example for text obscured attribute.')
48          .fontSize(30)
49          .width('600px')
50          .fontColor(Color.Black)
51          .border({ width: 1 })
52          .obscured([ObscuredReasons.PLACEHOLDER])
53        Text('Image set obscured attribute').fontSize(10).fontColor(Color.Black)
54        Image($r('app.media.icon'))
55          .width('200px')
56          .height('200px')
57          .obscured([ObscuredReasons.PLACEHOLDER])
58      }
59      .width('100%')
60    }
61    .height('100%')
62  }
63}
64```
65
66![obscured](figures/obscured.png)
67
68