1# QRCode 2 3用于显示单个二维码的组件。 4 5> **说明:** 6> 7> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8> 9> 二维码组件的像素点数量与内容有关,当组件尺寸过小时,可能出现无法展示内容的情况,此时需要适当调整组件尺寸。 10 11 12## 子组件 13 14无 15 16 17## 接口 18 19QRCode(value: string) 20 21从API version 9开始,该接口支持在ArkTS卡片中使用。 22 23**参数:** 24 25| 参数名 | 参数类型 | 必填 | 参数描述 | 26| -------- | -------- | -------- | -------- | 27| value | string | 是 | 二维码内容字符串。最大支持256个字符,若超出,则截取前256个字符。<br/>**说明:** <br/>该字符串内容确保有效,不支持null、undefined以及空内容。 | 28 29## 属性 30 31除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性。 32 33| 名称 | 参数类型 | 描述 | 34| -------- | -------- | -------- | 35| color | [ResourceColor](ts-types.md#resourcecolor) | 设置二维码颜色。<br/>默认值:Color.Black <br/>从API version 9开始,该接口支持在ArkTS卡片中使用。| 36| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | 设置二维码背景颜色。<br/>默认值:Color.White <br/>从API version 9开始,该接口支持在ArkTS卡片中使用。| 37 38 39## 事件 40 41通用事件支持[点击事件](ts-universal-events-click.md)、[触摸事件](ts-universal-events-touch.md)、[挂载卸载事件](ts-universal-events-show-hide.md)。 42 43 44## 示例 45 46```ts 47// xxx.ets 48@Entry 49@Component 50struct QRCodeExample { 51 private value: string = 'hello world' 52 build() { 53 Column({ space: 5 }) { 54 Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30) 55 QRCode(this.value).width(200).height(200) 56 57 // 设置二维码颜色 58 Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30) 59 QRCode(this.value).color(0xF7CE00).width(200).height(200) 60 61 // 设置二维码背景色 62 Text('backgroundColor').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30) 63 QRCode(this.value).width(200).height(200).backgroundColor(Color.Orange) 64 }.width('100%').margin({ top: 5 }) 65 } 66} 67``` 68 69 70