ts-drawing-components-rect.md 9.2 KB
Newer Older
Z
zengyawen 已提交
1 2 3 4
# Rect<a name="ZH-CN_TOPIC_0000001192755114"></a>

>![](../../public_sys-resources/icon-note.gif) **说明:** 
>该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
Z
zengyawen 已提交
5 6 7

矩形绘制组件。

Z
zengyawen 已提交
8 9 10 11
## 权限列表<a name="section53281531154915"></a>



Z
zengyawen 已提交
12 13 14 15 16 17 18 19 20 21
## 子组件<a name="section172855459342"></a>



## 接口<a name="section6391804354"></a>

Rect\(value:\{options?: \{width: Length,height: Length,radius?: Length | Array<Length\>\} | \{width: Length,height: Length,radiusWidth?: Length,radiusHeight?: Length\}\}\)

-   参数

Z
zengyawen 已提交
22
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="15.47%" id="mcps1.1.6.1.1"><p>参数名</p>
Z
zengyawen 已提交
23
    </th>
Z
zengyawen 已提交
24
    <th class="cellrowborder" valign="top" width="17.22%" id="mcps1.1.6.1.2"><p>参数类型</p>
Z
zengyawen 已提交
25
    </th>
Z
zengyawen 已提交
26
    <th class="cellrowborder" valign="top" width="12.49%" id="mcps1.1.6.1.3"><p>必填</p>
Z
zengyawen 已提交
27
    </th>
Z
zengyawen 已提交
28
    <th class="cellrowborder" valign="top" width="18.6%" id="mcps1.1.6.1.4"><p>默认值</p>
Z
zengyawen 已提交
29
    </th>
Z
zengyawen 已提交
30
    <th class="cellrowborder" valign="top" width="36.22%" id="mcps1.1.6.1.5"><p>参数描述</p>
Z
zengyawen 已提交
31 32 33
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
34
    <tbody><tr><td class="cellrowborder" valign="top" width="15.47%" headers="mcps1.1.6.1.1 "><p>options</p>
Z
zengyawen 已提交
35
    </td>
Z
zengyawen 已提交
36
    <td class="cellrowborder" valign="top" width="17.22%" headers="mcps1.1.6.1.2 "><p>Object</p>
Z
zengyawen 已提交
37
    </td>
Z
zengyawen 已提交
38
    <td class="cellrowborder" valign="top" width="12.49%" headers="mcps1.1.6.1.3 "><p>否</p>
Z
zengyawen 已提交
39
    </td>
Z
zengyawen 已提交
40
    <td class="cellrowborder" valign="top" width="18.6%" headers="mcps1.1.6.1.4 "><p>-</p>
Z
zengyawen 已提交
41
    </td>
Z
zengyawen 已提交
42
    <td class="cellrowborder" valign="top" width="36.22%" headers="mcps1.1.6.1.5 "><p>见<a href="#li1258118431037">options参数说明</a>。</p>
Z
zengyawen 已提交
43 44 45 46 47 48 49
    </td>
    </tr>
    </tbody>
    </table>

-   <a name="li1258118431037"></a>options参数说明

Z
zengyawen 已提交
50
    <table><thead align="left"><tr><th class="cellrowborder" valign="top" width="16.11%" id="mcps1.1.6.1.1"><p>参数名</p>
Z
zengyawen 已提交
51
    </th>
Z
zengyawen 已提交
52
    <th class="cellrowborder" valign="top" width="19.36%" id="mcps1.1.6.1.2"><p>参数类型</p>
Z
zengyawen 已提交
53
    </th>
Z
zengyawen 已提交
54
    <th class="cellrowborder" valign="top" width="9.15%" id="mcps1.1.6.1.3"><p>必填</p>
Z
zengyawen 已提交
55
    </th>
Z
zengyawen 已提交
56
    <th class="cellrowborder" valign="top" width="13.170000000000002%" id="mcps1.1.6.1.4"><p>默认值</p>
Z
zengyawen 已提交
57
    </th>
Z
zengyawen 已提交
58
    <th class="cellrowborder" valign="top" width="42.21%" id="mcps1.1.6.1.5"><p>参数描述</p>
Z
zengyawen 已提交
59 60 61
    </th>
    </tr>
    </thead>
Z
zengyawen 已提交
62
    <tbody><tr><td class="cellrowborder" valign="top" width="16.11%" headers="mcps1.1.6.1.1 "><p>width</p>
Z
zengyawen 已提交
63
    </td>
Z
zengyawen 已提交
64
    <td class="cellrowborder" valign="top" width="19.36%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
65
    </td>
Z
zengyawen 已提交
66
    <td class="cellrowborder" valign="top" width="9.15%" headers="mcps1.1.6.1.3 "><p>是</p>
Z
zengyawen 已提交
67
    </td>
Z
zengyawen 已提交
68
    <td class="cellrowborder" valign="top" width="13.170000000000002%" headers="mcps1.1.6.1.4 "><p>-</p>
Z
zengyawen 已提交
69
    </td>
Z
zengyawen 已提交
70
    <td class="cellrowborder" valign="top" width="42.21%" headers="mcps1.1.6.1.5 "><p>宽度。</p>
Z
zengyawen 已提交
71 72
    </td>
    </tr>
Z
zengyawen 已提交
73
    <tr><td class="cellrowborder" valign="top" width="16.11%" headers="mcps1.1.6.1.1 "><p>height</p>
Z
zengyawen 已提交
74
    </td>
Z
zengyawen 已提交
75
    <td class="cellrowborder" valign="top" width="19.36%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
76
    </td>
Z
zengyawen 已提交
77
    <td class="cellrowborder" valign="top" width="9.15%" headers="mcps1.1.6.1.3 "><p>是</p>
Z
zengyawen 已提交
78
    </td>
Z
zengyawen 已提交
79
    <td class="cellrowborder" valign="top" width="13.170000000000002%" headers="mcps1.1.6.1.4 "><p>-</p>
Z
zengyawen 已提交
80
    </td>
Z
zengyawen 已提交
81
    <td class="cellrowborder" valign="top" width="42.21%" headers="mcps1.1.6.1.5 "><p>高度。</p>
Z
zengyawen 已提交
82 83
    </td>
    </tr>
Z
zengyawen 已提交
84
    <tr><td class="cellrowborder" valign="top" width="16.11%" headers="mcps1.1.6.1.1 "><p>radius</p>
Z
zengyawen 已提交
85
    </td>
Z
zengyawen 已提交
86
    <td class="cellrowborder" valign="top" width="19.36%" headers="mcps1.1.6.1.2 "><p>Length | Array<span>&lt;</span><span>Length</span><span>&gt;</span></p>
Z
zengyawen 已提交
87
    </td>
Z
zengyawen 已提交
88
    <td class="cellrowborder" valign="top" width="9.15%" headers="mcps1.1.6.1.3 "><p>否</p>
Z
zengyawen 已提交
89
    </td>
Z
zengyawen 已提交
90
    <td class="cellrowborder" valign="top" width="13.170000000000002%" headers="mcps1.1.6.1.4 "><p>0</p>
Z
zengyawen 已提交
91
    </td>
Z
zengyawen 已提交
92
    <td class="cellrowborder" valign="top" width="42.21%" headers="mcps1.1.6.1.5 "><p>圆角半径,支持分别设置四个角的圆角度数。</p>
Z
zengyawen 已提交
93 94
    </td>
    </tr>
Z
zengyawen 已提交
95
    <tr><td class="cellrowborder" valign="top" width="16.11%" headers="mcps1.1.6.1.1 "><p>radiusWidth</p>
Z
zengyawen 已提交
96
    </td>
Z
zengyawen 已提交
97
    <td class="cellrowborder" valign="top" width="19.36%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
98
    </td>
Z
zengyawen 已提交
99
    <td class="cellrowborder" valign="top" width="9.15%" headers="mcps1.1.6.1.3 "><p>否</p>
Z
zengyawen 已提交
100
    </td>
Z
zengyawen 已提交
101
    <td class="cellrowborder" valign="top" width="13.170000000000002%" headers="mcps1.1.6.1.4 "><p>0</p>
Z
zengyawen 已提交
102
    </td>
Z
zengyawen 已提交
103
    <td class="cellrowborder" valign="top" width="42.21%" headers="mcps1.1.6.1.5 "><p>圆角宽度。</p>
Z
zengyawen 已提交
104 105
    </td>
    </tr>
Z
zengyawen 已提交
106
    <tr><td class="cellrowborder" valign="top" width="16.11%" headers="mcps1.1.6.1.1 "><p>radiusHeight</p>
Z
zengyawen 已提交
107
    </td>
Z
zengyawen 已提交
108
    <td class="cellrowborder" valign="top" width="19.36%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
109
    </td>
Z
zengyawen 已提交
110
    <td class="cellrowborder" valign="top" width="9.15%" headers="mcps1.1.6.1.3 "><p>否</p>
Z
zengyawen 已提交
111
    </td>
Z
zengyawen 已提交
112
    <td class="cellrowborder" valign="top" width="13.170000000000002%" headers="mcps1.1.6.1.4 "><p>0</p>
Z
zengyawen 已提交
113
    </td>
Z
zengyawen 已提交
114
    <td class="cellrowborder" valign="top" width="42.21%" headers="mcps1.1.6.1.5 "><p>圆角高度。</p>
Z
zengyawen 已提交
115 116 117 118 119 120 121 122
    </td>
    </tr>
    </tbody>
    </table>


## 属性<a name="section208511436173518"></a>

Z
zengyawen 已提交
123
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.1"><p>参数名称</p>
Z
zengyawen 已提交
124
</th>
Z
zengyawen 已提交
125
<th class="cellrowborder" valign="top" width="22.009999999999998%" id="mcps1.1.6.1.2"><p>参数类型</p>
Z
zengyawen 已提交
126
</th>
Z
zengyawen 已提交
127
<th class="cellrowborder" valign="top" width="17.990000000000002%" id="mcps1.1.6.1.3"><p>默认值</p>
Z
zengyawen 已提交
128
</th>
Z
zengyawen 已提交
129
<th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.4"><p>必填</p>
Z
zengyawen 已提交
130
</th>
Z
zengyawen 已提交
131
<th class="cellrowborder" valign="top" width="20%" id="mcps1.1.6.1.5"><p>参数描述</p>
Z
zengyawen 已提交
132 133 134
</th>
</tr>
</thead>
Z
zengyawen 已提交
135
<tbody><tr><td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.1 "><p>width</p>
Z
zengyawen 已提交
136
</td>
Z
zengyawen 已提交
137
<td class="cellrowborder" valign="top" width="22.009999999999998%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
138
</td>
Z
zengyawen 已提交
139
<td class="cellrowborder" valign="top" width="17.990000000000002%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
140
</td>
Z
zengyawen 已提交
141
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
142
</td>
Z
zengyawen 已提交
143
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.5 "><p>宽度。</p>
Z
zengyawen 已提交
144 145
</td>
</tr>
Z
zengyawen 已提交
146
<tr><td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.1 "><p>height</p>
Z
zengyawen 已提交
147
</td>
Z
zengyawen 已提交
148
<td class="cellrowborder" valign="top" width="22.009999999999998%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
149
</td>
Z
zengyawen 已提交
150
<td class="cellrowborder" valign="top" width="17.990000000000002%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
151
</td>
Z
zengyawen 已提交
152
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
153
</td>
Z
zengyawen 已提交
154
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.5 "><p>高度。</p>
Z
zengyawen 已提交
155 156
</td>
</tr>
Z
zengyawen 已提交
157
<tr><td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.1 "><p>radiusWidth</p>
Z
zengyawen 已提交
158
</td>
Z
zengyawen 已提交
159
<td class="cellrowborder" valign="top" width="22.009999999999998%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
160
</td>
Z
zengyawen 已提交
161
<td class="cellrowborder" valign="top" width="17.990000000000002%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
162
</td>
Z
zengyawen 已提交
163
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
164
</td>
Z
zengyawen 已提交
165
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.5 "><p>圆角的宽度,仅设置宽时宽高一致。</p>
Z
zengyawen 已提交
166 167
</td>
</tr>
Z
zengyawen 已提交
168
<tr><td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.1 "><p>radiusHeight</p>
Z
zengyawen 已提交
169
</td>
Z
zengyawen 已提交
170
<td class="cellrowborder" valign="top" width="22.009999999999998%" headers="mcps1.1.6.1.2 "><p>Length</p>
Z
zengyawen 已提交
171
</td>
Z
zengyawen 已提交
172
<td class="cellrowborder" valign="top" width="17.990000000000002%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
173
</td>
Z
zengyawen 已提交
174
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
175
</td>
Z
zengyawen 已提交
176
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.5 "><p>圆角的高度,仅设置高时宽高一致。</p>
Z
zengyawen 已提交
177 178
</td>
</tr>
Z
zengyawen 已提交
179
<tr><td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.1 "><p>radius</p>
Z
zengyawen 已提交
180
</td>
Z
zengyawen 已提交
181
<td class="cellrowborder" valign="top" width="22.009999999999998%" headers="mcps1.1.6.1.2 "><p>Length | Array<span>&lt;</span><span>Length</span><span>&gt;</span></p>
Z
zengyawen 已提交
182
</td>
Z
zengyawen 已提交
183
<td class="cellrowborder" valign="top" width="17.990000000000002%" headers="mcps1.1.6.1.3 "><p>0</p>
Z
zengyawen 已提交
184
</td>
Z
zengyawen 已提交
185
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.4 "><p></p>
Z
zengyawen 已提交
186
</td>
Z
zengyawen 已提交
187
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.1.6.1.5 "><p>圆角大小。</p>
Z
zengyawen 已提交
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
</td>
</tr>
</tbody>
</table>

## 示例<a name="section4459736105512"></a>

```
@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 })
  }
}
```

![](figures/rect.png)