1e41f4b71Sopenharmony_ci# Rect 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci矩形绘制组件。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## 子组件 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci无 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## 接口 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciRect(value?: {width?: string | number,height?: string | number,radius?: string | number | Array<string | number>} |{width?: string | number,height?: string | number,radiusWidth?: string | number,radiusHeight?: string | number}) 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**参数:** 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 28e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 29e41f4b71Sopenharmony_ci| value | {width?: string \| number,height?: string \| number,radius?: string \| number \| Array<string \| number>} \| {width?: string \| number,height?: string \| number,radiusWidth?: string \| number,radiusHeight?: string \| number} | 否 | width:宽度。<br/>默认值:0<br/>异常值按照默认值处理。<br/>height: 高度。<br/>默认值:0<br/>异常值按照默认值处理。<br/>radius:圆角半径,支持分别设置四个角的圆角度数。<br/>该属性和radiusWidth/radiusHeight属性效果类似,在组合使用时优先于radiusWidth/radiusHeight生效<br/>默认值:0<br/>异常值按照默认值处理。<br/>radiusWidth:圆角宽度。<br/>默认值:0<br/>异常值按照默认值处理。<br/>radiusHeight:圆角高度。<br/>默认值:0<br/>异常值按照默认值处理。| 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci## 属性 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci### radiusWidth 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ciradiusWidth(value: number | string) 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci设置圆角的宽度,仅设置宽时宽高一致。 异常值按照默认值处理。 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**卡片能力:** 从API version 7开始,该接口支持在ArkTS卡片中使用。 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**参数:** 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 50e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | -------------------------- | 51e41f4b71Sopenharmony_ci| value | number \| string | 是 | 圆角的宽度。<br/>默认值:0 | 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci### radiusHeight 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ciradiusHeight(value: number | string) 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci设置圆角的高度,仅设置高时宽高一致。 异常值按照默认值处理。 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**卡片能力:** 从API version 7开始,该接口支持在ArkTS卡片中使用。 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**参数:** 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 68e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | -------------------------- | 69e41f4b71Sopenharmony_ci| value | number \| string | 是 | 圆角的高度。<br/>默认值:0 | 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci### radius 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciradius(value: number | string | Array<string | number>) 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci设置圆角半径大小。 异常值按照默认值处理。 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**参数:** 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 86e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ---------------------------- | 87e41f4b71Sopenharmony_ci| value | number \| string \| Array<string \| number> | 是 | 圆角半径大小。<br/>默认值:0 | 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci### fill 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_cifill(value: ResourceColor) 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci设置填充区域颜色。异常值按照默认值处理。 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci**参数:** 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 104e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------------------- | 105e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | 是 | 填充区域颜色。<br/>默认值:Color.Black | 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci### fillOpacity 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_cifillOpacity(value: number | string | Resource) 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci设置填充区域透明度。取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0,其余异常值按1.0处理。 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**参数:** 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 122e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------ | 123e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | 是 | 填充区域透明度。<br/>默认值:1 | 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci### stroke 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_cistroke(value: ResourceColor) 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci设置边框颜色,不设置时,默认没有边框。异常值不会绘制边框。 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**参数:** 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 140e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------- | 141e41f4b71Sopenharmony_ci| value | [ResourceColor](ts-types.md#resourcecolor) | 是 | 边框颜色。 | 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci### strokeDashArray 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_cistrokeDashArray(value: Array<any>) 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci设置边框间隙。异常值按照默认值处理。 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**参数:** 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 158e41f4b71Sopenharmony_ci| ------ | ---------------- | ---- | ------------------------- | 159e41f4b71Sopenharmony_ci| value | Array<any> | 是 | 边框间隙。<br/>默认值:[] | 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci### strokeDashOffset 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_cistrokeDashOffset(value: number | string) 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci设置边框绘制起点的偏移量。异常值按照默认值处理。 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci**参数:** 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 176e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | ------------------------------------ | 177e41f4b71Sopenharmony_ci| value | number \| string | 是 | 边框绘制起点的偏移量。<br/>默认值:0 | 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci### strokeLineCap 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_cistrokeLineCap(value: LineCapStyle) 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci设置边框端点绘制样式。 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci**参数:** 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 194e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------- | ---- | ------------------------------------------------ | 195e41f4b71Sopenharmony_ci| value | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | 是 | 边框端点绘制样式。<br/>默认值:LineCapStyle.Butt | 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci### strokeLineJoin 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_cistrokeLineJoin(value: LineJoinStyle) 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci设置边框拐角绘制样式。 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**参数:** 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 212e41f4b71Sopenharmony_ci| ------ | --------------------------------------------------- | ---- | -------------------------------------------------- | 213e41f4b71Sopenharmony_ci| value | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | 是 | 边框拐角绘制样式。<br/>默认值:LineJoinStyle.Miter | 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci### strokeMiterLimit 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_cistrokeMiterLimit(value: number | string) 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci设置斜接长度与边框宽度比值的极限值。斜接长度表示外边框外边交点到内边交点的距离,边框宽度即strokeWidth属性的值。该属性取值需在strokeLineJoin属性取值LineJoinStyle.Miter时生效。 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci该属性的合法值范围应当大于等于1.0,当取值范围在[0,1)时按1.0处理,其余异常值按默认值处理。 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci**参数:** 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 232e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | ---------------------------------------------- | 233e41f4b71Sopenharmony_ci| value | number \| string | 是 | 斜接长度与边框宽度比值的极限值。<br/>默认值:4 | 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci### strokeOpacity 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_cistrokeOpacity(value: number | string | Resource) 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci设置边框透明度。该属性的取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0,其余异常值按1.0处理 。 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci**参数:** 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 250e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------------- | 251e41f4b71Sopenharmony_ci| value | number \| string \| [Resource](ts-types.md#resource) | 是 | 边框透明度。<br/>默认值:1 | 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci### strokeWidth 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_cistrokeWidth(value: Length) 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci设置边框宽度。该属性若为string类型, 暂不支持百分比,百分比按照1px处理。 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**参数:** 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 268e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------ | 269e41f4b71Sopenharmony_ci| value | [Length](ts-types.md#length) | 是 | 边框宽度。<br/>默认值:1 | 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci### antiAlias 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ciantiAlias(value: boolean) 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci设置是否开启抗锯齿效果。 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**参数:** 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 286e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------- | 287e41f4b71Sopenharmony_ci| value | boolean | 是 | 是否开启抗锯齿效果。<br/>默认值:true | 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci## 示例 290e41f4b71Sopenharmony_ci### 示例1 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci```ts 293e41f4b71Sopenharmony_ci// xxx.ets 294e41f4b71Sopenharmony_ci@Entry 295e41f4b71Sopenharmony_ci@Component 296e41f4b71Sopenharmony_cistruct RectExample { 297e41f4b71Sopenharmony_ci build() { 298e41f4b71Sopenharmony_ci Column({ space: 10 }) { 299e41f4b71Sopenharmony_ci Text('normal').fontSize(11).fontColor(0xCCCCCC).width('90%') 300e41f4b71Sopenharmony_ci // 绘制90% * 50的矩形 301e41f4b71Sopenharmony_ci Column({ space: 5 }) { 302e41f4b71Sopenharmony_ci Text('normal').fontSize(9).fontColor(0xCCCCCC).width('90%') 303e41f4b71Sopenharmony_ci // 绘制90% * 50矩形 304e41f4b71Sopenharmony_ci Rect({ width: '90%', height: 50 }) 305e41f4b71Sopenharmony_ci .fill(Color.Pink) 306e41f4b71Sopenharmony_ci // 绘制90% * 50的矩形框 307e41f4b71Sopenharmony_ci Rect() 308e41f4b71Sopenharmony_ci .width('90%') 309e41f4b71Sopenharmony_ci .height(50) 310e41f4b71Sopenharmony_ci .fillOpacity(0) 311e41f4b71Sopenharmony_ci .stroke(Color.Red) 312e41f4b71Sopenharmony_ci .strokeWidth(3) 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci Text('with rounded corners').fontSize(11).fontColor(0xCCCCCC).width('90%') 315e41f4b71Sopenharmony_ci // 绘制90% * 80的矩形, 圆角宽高分别为40、20 316e41f4b71Sopenharmony_ci Rect({ width: '90%', height: 80 }) 317e41f4b71Sopenharmony_ci .radiusHeight(20) 318e41f4b71Sopenharmony_ci .radiusWidth(40) 319e41f4b71Sopenharmony_ci .fill(Color.Pink) 320e41f4b71Sopenharmony_ci // 绘制90% * 80的矩形, 圆角宽高为20 321e41f4b71Sopenharmony_ci Rect({ width: '90%', height: 80 }) 322e41f4b71Sopenharmony_ci .radius(20) 323e41f4b71Sopenharmony_ci .fill(Color.Pink) 324e41f4b71Sopenharmony_ci .stroke(Color.Transparent) 325e41f4b71Sopenharmony_ci }.width('100%').margin({ top: 10 }) 326e41f4b71Sopenharmony_ci // 绘制90% * 50矩形, 左上圆角宽高40,右上圆角宽高20,右下圆角宽高40,左下圆角宽高20 327e41f4b71Sopenharmony_ci Rect({ width: '90%', height: 80 }) 328e41f4b71Sopenharmony_ci .radius([[40, 40], [20, 20], [40, 40], [20, 20]]) 329e41f4b71Sopenharmony_ci .fill(Color.Pink) 330e41f4b71Sopenharmony_ci }.width('100%').margin({ top: 5 }) 331e41f4b71Sopenharmony_ci } 332e41f4b71Sopenharmony_ci} 333e41f4b71Sopenharmony_ci``` 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci### 示例2 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci```ts 340e41f4b71Sopenharmony_ci// xxx.ets 341e41f4b71Sopenharmony_ci@Entry 342e41f4b71Sopenharmony_ci@Component 343e41f4b71Sopenharmony_cistruct RectExample { 344e41f4b71Sopenharmony_ci build() { 345e41f4b71Sopenharmony_ci Column({ space: 10 }) { 346e41f4b71Sopenharmony_ci Column() 347e41f4b71Sopenharmony_ci .width(100) 348e41f4b71Sopenharmony_ci .height(100) 349e41f4b71Sopenharmony_ci .linearGradient({ 350e41f4b71Sopenharmony_ci direction: GradientDirection.Right, 351e41f4b71Sopenharmony_ci colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]] 352e41f4b71Sopenharmony_ci }) 353e41f4b71Sopenharmony_ci .clip(new Rect({ width: 100, height: 100, radius: 40 })) 354e41f4b71Sopenharmony_ci Rect() 355e41f4b71Sopenharmony_ci .width(100) 356e41f4b71Sopenharmony_ci .height(100) 357e41f4b71Sopenharmony_ci // 设置矩形填充,如果需要显示背景的渐变色,请设置区域透明度.fillOpacity(0.0) 358e41f4b71Sopenharmony_ci .fill(Color.Pink) 359e41f4b71Sopenharmony_ci // 设置倒角为40 360e41f4b71Sopenharmony_ci .radius(40) 361e41f4b71Sopenharmony_ci .stroke(Color.Black) 362e41f4b71Sopenharmony_ci // 设置渐变色,仅100*100的矩形区域生效,渐变色的边界不包含倒角 363e41f4b71Sopenharmony_ci .linearGradient({ 364e41f4b71Sopenharmony_ci direction: GradientDirection.Right, 365e41f4b71Sopenharmony_ci colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]] 366e41f4b71Sopenharmony_ci }) 367e41f4b71Sopenharmony_ci } 368e41f4b71Sopenharmony_ci } 369e41f4b71Sopenharmony_ci} 370e41f4b71Sopenharmony_ci``` 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci 373