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