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

H
HelloCrease 已提交
3
>  **说明:**
H
HelloCrease 已提交
4 5
>
>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
Z
zengyawen 已提交
6

Z
zengyawen 已提交
7 8 9

矩形绘制组件。

Z
zengyawen 已提交
10 11

## 权限列表
Z
zengyawen 已提交
12 13 14



Z
zengyawen 已提交
15 16

## 子组件
Z
zengyawen 已提交
17 18 19



Z
zengyawen 已提交
20 21 22

## 接口

L
luoying_ace_admin 已提交
23 24
Rect(options?: {width?: string | number,height?: string | number,radius?: string | number | Array<string | number>} |
  {width?: string | number,height?: string | number,radiusWidth?: string | number,radiusHeight?: string | number})
Z
zengyawen 已提交
25

L
luoying_ace_admin 已提交
26 27 28 29 30 31 32 33
- 参数
  | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | 
  | -------- | -------- | -------- | -------- | -------- |
  | width | string \| number | 否 | 0 | 宽度。 | 
  | height | string \| number | 否 | 0 | 高度。 | 
  | radius | string \| number \| Array<string \| number> | 否 | 0 | 圆角半径,支持分别设置四个角的圆角度数。 | 
  | radiusWidth | string \| number | 否 | 0 | 圆角宽度。 | 
  | radiusHeight | string \| number | 否 | 0 | 圆角高度。 | 
Z
zengyawen 已提交
34 35 36 37


## 属性

L
luoying_ace_admin 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:

| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | 
| -------- | -------- | -------- | -------- | -------- |
| radiusWidth | string \| number | 0 | 否 | 圆角的宽度,仅设置宽时宽高一致。 | 
| radiusHeight | string \| number | 0 | 否 | 圆角的高度,仅设置高时宽高一致。 | 
| radius | string \| number \| Array<string \| number> | 0 | 否 | 圆角半径大小。 |
| fill | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置填充区域颜色。 |
| fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 |
| stroke | [ResourceColor](../../ui/ts-types.md) | Color.Black | 否 | 设置线条颜色。 |
| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 |
| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 |
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 |
| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 |
| strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 |
| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 |
| strokeWidth | Length | 1 | 否 | 设置线条宽度。 |
| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
Z
zengyawen 已提交
56 57 58


## 示例
Z
zengyawen 已提交
59

H
HelloCrease 已提交
60 61
```ts
// xxx.ets
Z
zengyawen 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
@Entry
@Component
struct RectExample {
  build() {
    Column({ space: 5 }) {
      Text('normal').fontSize(9).fontColor(0xCCCCCC).width('90%')
      // 绘制90% * 50矩形
      Rect({ width: '90%', height: 50 })
      // 绘制90% * 50矩形
      Rect().width('90%').height(50)

      Text('with rounded corners').fontSize(9).fontColor(0xCCCCCC).width('90%')
      // 绘制90% * 50矩形, 圆角宽高20
      Rect({ width: '90%', height: 50 }).radiusHeight(20).radiusWidth(20)
      // 绘制90% * 50矩形, 圆角宽高20
      Rect({ width: '90%', height: 50 }).radius(20)
    }.width('100%').margin({ top: 5 })
  }
}
```

Z
zengyawen 已提交
83
![zh-cn_image_0000001174264386](figures/zh-cn_image_0000001174264386.png)