ts-basic-components-qrcode.md 2.4 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.
E
ester.zhou 已提交
8 9
> 
> The number of pixels of the **\<QRCode>** component is subject to the content. If the component size is not large enough, the content may fail to be displayed. In this case, you need to resize the component.
Z
zengyawen 已提交
10

Z
zengyawen 已提交
11 12

## Child Components
Z
zengyawen 已提交
13

14
Not supported
Z
zengyawen 已提交
15

Z
zengyawen 已提交
16 17 18 19 20

## APIs

QRCode(value: string)

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

E
ester.zhou 已提交
23
**Parameters**
Z
zengyawen 已提交
24

E
ester.zhou 已提交
25 26
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
27
| value | string | Yes| Content of the QR code. A maximum of 256 characters are supported. If the number of characters exceeds 256, the first 256 characters are used.<br>**NOTE**<br>The string cannot be **null**, **undefined**, or empty.|
Z
zengyawen 已提交
28 29 30

## Attributes

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

| Name| Type| Description|
| -------- | -------- | -------- |
E
ester.zhou 已提交
35 36
| 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 已提交
37 38 39


## Events
Z
zengyawen 已提交
40

E
ester.zhou 已提交
41
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 已提交
42 43


Z
zengyawen 已提交
44 45
## Example

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

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

      // 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 已提交
64 65 66 67 68
    }.width('100%').margin({ top: 5 })
  }
}
```

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