ts-drawing-components-rect.md 3.5 KB
Newer Older
Z
zengyawen 已提交
1
# Rect
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
The **\<Rect>** component is used to draw a rectangle.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5 6 7
>  **NOTE**
>
>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8 9 10


## Child Components
Z
zengyawen 已提交
11

E
ester.zhou 已提交
12
Not supported
Z
zengyawen 已提交
13 14


Z
zengyawen 已提交
15 16
## APIs

E
ester.zhou 已提交
17
Rect(value?: {width?: string | number,height?: string | number,radius?: string | number | Array&lt;string | number&gt;} |
E
ester.zhou 已提交
18
  {width?: string | number,height?: string | number,radiusWidth?: string | number,radiusHeight?: string | number})
Z
zengyawen 已提交
19 20

- Parameters
E
ester.zhou 已提交
21
  | Name| Type| Mandatory| Default Value| Description| 
Z
zengyawen 已提交
22
  | -------- | -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
23 24 25 26 27
  | width | string \| number | No| 0 | Width.| 
  | height | string \| number | No| 0 | Height.| 
  | radius | string \| number \| Array&lt;string \| number&gt; | No| 0 | Radius of the rounded corner. You can set separate radiuses for four rounded corners.| 
  | radiusWidth | string \| number | No| 0 | Width of the rounded corner.| 
  | radiusHeight | string \| number | No| 0 | Height of the rounded corner.| 
Z
zengyawen 已提交
28 29 30 31


## Attributes

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

E
ester.zhou 已提交
34
| Name| Type| Default Value| Mandatory| Description| 
Z
zengyawen 已提交
35
| -------- | -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
36 37
| radiusWidth | string \| number | 0 | No| Width of the rounded corner. The width and height are the same when only the width is set.| 
| radiusHeight | string \| number | 0 | No| Height of the rounded corner. The width and height are the same only when the height is set.| 
E
ester.zhou 已提交
38
| radius | string \| number \| Array&lt;string \| number&gt; | 0 | No| Radius of the rounded corner. You can set separate radiuses for four rounded corners.|
E
ester.zhou 已提交
39 40 41
| fill | [ResourceColor](ts-types.md#resourcecolor) | Color.Black | No| Color of the fill area.|
| fillOpacity | number \| string \| [Resource](ts-types.md#resource)| 1 | No| Opacity of the fill area.|
| stroke | [ResourceColor](ts-types.md#resourcecolor) | Color.Black | No| Stroke color.|
E
ester.zhou 已提交
42 43 44 45 46
| strokeDashArray | Array&lt;Length&gt; | [] | No| Stroke dash.|
| strokeDashOffset | number \| string | 0 | No| Offset of the start point for drawing the stroke.|
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | No| Cap style of the stroke.|
| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | No| Join style of the stroke.|
| strokeMiterLimit | number \| string | 4 | No| Limit value when the sharp angle is drawn as a miter.|
E
ester.zhou 已提交
47
| strokeOpacity | number \| string \| [Resource](ts-types.md#resource)| 1 | No| Stroke opacity.|
E
ester.zhou 已提交
48 49
| strokeWidth | Length | 1 | No| Stroke width.|
| antiAlias | boolean | true | No| Whether anti-aliasing is enabled.|
Z
zengyawen 已提交
50 51 52 53


## Example

Mr-YX's avatar
Mr-YX 已提交
54
```ts
E
ester.zhou 已提交
55
// xxx.ets
Z
zengyawen 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
@Entry
@Component
struct RectExample {
  build() {
    Column({ space: 5 }) {
      Text('normal').fontSize(9).fontColor(0xCCCCCC).width('90%')
      // Draw a 90% x 50 rectangle.
      Rect({ width: '90%', height: 50 })
      // Draw a 90% x 50 rectangle.
      Rect().width('90%').height(50)

      Text('with rounded corners').fontSize(9).fontColor(0xCCCCCC).width('90%')
      // Draw a 90% x 50 rectangle with the width and height of the rounded corner being 20.
      Rect({ width: '90%', height: 50 }).radiusHeight(20).radiusWidth(20)
      // Draw a 90% x 50 rectangle with the width and height of the rounded corner being 20.
      Rect({ width: '90%', height: 50 }).radius(20)
    }.width('100%').margin({ top: 5 })
  }
}
```

E
ester.zhou 已提交
77
![en-us_image_0000001212218454](figures/en-us_image_0000001212218454.png)