1# Rect 2 3> **说明:** 4> 5> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 6 7 8矩形绘制组件。 9 10 11## 权限列表 12 13无 14 15 16## 子组件 17 18无 19 20 21## 接口 22 23Rect(options?: {width?: string | number,height?: string | number,radius?: string | number | Array<string | number>} | 24 {width?: string | number,height?: string | number,radiusWidth?: string | number,radiusHeight?: string | number}) 25 26**参数:** 27 28| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | 29| -------- | -------- | -------- | -------- | -------- | 30| width | string \| number | 否 | 0 | 宽度。 | 31| height | string \| number | 否 | 0 | 高度。 | 32| radius | string \| number \| Array<string \| number> | 否 | 0 | 圆角半径,支持分别设置四个角的圆角度数。 | 33| radiusWidth | string \| number | 否 | 0 | 圆角宽度。 | 34| radiusHeight | string \| number | 否 | 0 | 圆角高度。 | 35 36 37## 属性 38 39除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: 40 41| 名称 | 类型 | 默认值 | 描述 | 42| -------- | -------- | -------- | -------- | 43| radiusWidth | string \| number | 0 | 圆角的宽度,仅设置宽时宽高一致。 | 44| radiusHeight | string \| number | 0 | 圆角的高度,仅设置高时宽高一致。 | 45| radius | string \| number \| Array<string \| number> | 0 | 圆角半径大小。 | 46| fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 设置填充区域颜色。 | 47| fillOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 设置填充区域透明度。 | 48| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 设置边框颜色,不设置时,默认没有边框线条。 | 49| strokeDashArray | Array<Length> | [] | 设置边框间隙。 | 50| strokeDashOffset | number \| string | 0 | 边框绘制起点的偏移量。 | 51| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 设置边框端点绘制样式。 | 52| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 设置边框拐角绘制样式。 | 53| strokeMiterLimit | number \| string | 4 | 设置斜接长度与边框宽度比值的极限值。斜接长度表示外边框外边交点到内边交点的距离,边框宽度即strokeWidth属性的值。<br/>**说明:**<br/>该属性取值需大于等于1,且在strokeLineJoin属性取值LineJoinStyle.Miter时生效。 | 54| strokeOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 设置边框透明度。<br/>**说明:**<br/>该属性的取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0。 | 55| strokeWidth | Length | 1 | 设置边框宽度。 | 56| antiAlias | boolean | true | 是否开启抗锯齿效果。 | 57 58 59## 示例 60 61```ts 62// xxx.ets 63@Entry 64@Component 65struct RectExample { 66 build() { 67 Column({ space: 10 }) { 68 Text('normal').fontSize(11).fontColor(0xCCCCCC).width('90%') 69 // 绘制90% * 50的矩形 70 Column({ space: 5 }) { 71 Text('normal').fontSize(9).fontColor(0xCCCCCC).width('90%') 72 // 绘制90% * 50矩形 73 Rect({ width: '90%', height: 50 }) 74 .fill(Color.Pink) 75 // 绘制90% * 50的矩形框 76 Rect() 77 .width('90%') 78 .height(50) 79 .fillOpacity(0) 80 .stroke(Color.Red) 81 .strokeWidth(3) 82 83 Text('with rounded corners').fontSize(11).fontColor(0xCCCCCC).width('90%') 84 // 绘制90% * 80的矩形, 圆角宽高分别为40、20 85 Rect({ width: '90%', height: 80 }) 86 .radiusHeight(20) 87 .radiusWidth(40) 88 .fill(Color.Pink) 89 // 绘制90% * 80的矩形, 圆角宽高为20 90 Rect({ width: '90%', height: 80 }) 91 .radius(20) 92 .fill(Color.Pink) 93 }.width('100%').margin({ top: 10 }) 94 // 绘制90% * 50矩形, 左上圆角宽高40,右上圆角宽高20,右下圆角宽高40,左下圆角宽高20 95 Rect({ width: '90%', height: 80 }) 96 .radius([[40, 40], [20, 20], [40, 40], [20, 20]]) 97 .fill(Color.Pink) 98 }.width('100%').margin({ top: 5 }) 99 } 100} 101``` 102 103 104