ts-basic-components-qrcode.md 2.0 KB
Newer Older
Z
zengyawen 已提交
1
# QRCode
Z
zengyawen 已提交
2

3
The **\<QRCode>** component is used to display a QR code.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5
> **NOTE**
6
>
E
ester.zhou 已提交
7
> This component is 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

## Child Components
Z
zengyawen 已提交
11

12
Not supported
Z
zengyawen 已提交
13

Z
zengyawen 已提交
14 15 16 17 18

## APIs

QRCode(value: string)

E
ester.zhou 已提交
19 20
Since API version 9, this API is supported in ArkTS widgets.

E
ester.zhou 已提交
21
**Parameters**
Z
zengyawen 已提交
22

E
ester.zhou 已提交
23 24 25
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string | Yes| Content of the QR code.|
Z
zengyawen 已提交
26 27 28

## Attributes

E
ester.zhou 已提交
29 30 31 32
In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.

| Name| Type| Description|
| -------- | -------- | -------- |
E
ester.zhou 已提交
33 34
| color | [ResourceColor](ts-types.md#resourcecolor) | Color of the QR code.<br>Default value: **Color.Black**<br>Since API version 9, this API is supported in ArkTS widgets.|
| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | Background color of the QR code.<br>Default value: **Color.White**<br>Since API version 9, this API is supported in ArkTS widgets.|
Z
zengyawen 已提交
35 36 37


## Events
Z
zengyawen 已提交
38

E
ester.zhou 已提交
39
Among the universal events, the [click event](ts-universal-events-click.md), [touch event](ts-universal-events-touch.md), and [show/hide event](ts-universal-events-show-hide.md) are supported.
Z
zengyawen 已提交
40 41


Z
zengyawen 已提交
42 43
## Example

44 45
```ts
// xxx.ets
Z
zengyawen 已提交
46 47 48 49 50 51
@Entry
@Component
struct QRCodeExample {
  private value: string = 'hello world'
  build() {
    Column({ space: 5 }) {
E
ester.zhou 已提交
52
      Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
Z
zengyawen 已提交
53 54
      QRCode(this.value).width(200).height(200)

E
ester.zhou 已提交
55 56
      // Set the color for the QR code.
      Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
Z
zengyawen 已提交
57
      QRCode(this.value).color(0xF7CE00).width(200).height(200)
E
ester.zhou 已提交
58 59 60 61

      // Set the background color for the QR code.
      Text('backgroundColor').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
      QRCode(this.value).width(200).height(200).backgroundColor(Color.Orange)
Z
zengyawen 已提交
62 63 64 65 66
    }.width('100%').margin({ top: 5 })
  }
}
```

E
ester.zhou 已提交
67
![qrcode](figures/qrcode.png)