ts-drawing-components-circle.md 3.8 KB
Newer Older
Z
zengyawen 已提交
1
# Circle
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3
 The **\<Circle>** component is used to draw a circle.
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

Z
zengyawen 已提交
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
Circle(options?: {width?: string | number, height?: string | number})
Z
zengyawen 已提交
18

E
ester.zhou 已提交
19 20
Since API version 9, this API is supported in ArkTS widgets.

E
ester.zhou 已提交
21 22 23 24 25 26
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| width | string \| number | No| Width of the circle.<br>Default value: **0**|
| height | string \| number | No| Height of the circle.<br>Default value: **0**|
Z
zengyawen 已提交
27 28 29

## Attributes

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

E
ester.zhou 已提交
32 33
| Name| Type| Description|
| -------- | -------- | -------- |
E
ester.zhou 已提交
34 35 36 37 38 39
| fill | [ResourceColor](ts-types.md) | Color of the fill area.<br>Default value: **Color.Black**<br>Since API version 9, this API is supported in ArkTS widgets.|
| fillOpacity | number \| string \| [Resource](ts-types.md#resource)| Opacity of the fill area.<br>Default value: **1**<br>Since API version 9, this API is supported in ArkTS widgets.|
| stroke | [ResourceColor](ts-types.md) | Stroke color. If this attribute is not set, the component does not have any stroke.<br>Since API version 9, this API is supported in ArkTS widgets.|
| strokeDashArray | Array&lt;Length&gt; | Stroke dashes.<br>Default value: **[]**<br>Since API version 9, this API is supported in ArkTS widgets.|
| strokeDashOffset | number \| string  | Offset of the start point for drawing the stroke.<br>Default value: **0**<br>Since API version 9, this API is supported in ArkTS widgets.|
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | Cap style of the stroke.<br>Default value: **LineCapStyle.Butt**<br>Since API version 9, this API is supported in ArkTS widgets.|
E
ester.zhou 已提交
40
| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | Join style of the stroke.<br>Default value: **LineJoinStyle.Miter**<br>Since API version 9, this API is supported in ArkTS widgets.<br>**NOTE**<br>This attribute does not work for the **\<circle>** component, which does not have corners.|
E
ester.zhou 已提交
41 42
| strokeMiterLimit | number \| string | Limit on the ratio of the miter length to the value of **strokeWidth** used to draw a miter join.<br>Default value: **4**<br>Since API version 9, this API is supported in ArkTS widgets.<br>**NOTE**<br>This attribute does not take effect for the **\<Circle>** component, because it does not have a miter join.|
| strokeOpacity | number \| string \| [Resource](ts-types.md#resource)| Stroke opacity.<br>Default value: **1**<br>Since API version 9, this API is supported in ArkTS widgets.<br>**NOTE**<br>The value range is [0.0, 1.0]. If the set value is less than 0.0, **0.0** will be used. If the set value is greater than 1.0, **1.0** will be used.|
E
ester.zhou 已提交
43
| strokeWidth | Length | Stroke width.<br>Default value: **1**<br>Since API version 9, this API is supported in ArkTS widgets.<br>**NOTE**<br>The value cannot be a percentage.|
E
ester.zhou 已提交
44
| antiAlias | boolean | Whether anti-aliasing is enabled.<br>Default value: **true**<br>Since API version 9, this API is supported in ArkTS widgets.|
Z
zengyawen 已提交
45 46 47 48


## Example

Mr-YX's avatar
Mr-YX 已提交
49
```ts
E
ester.zhou 已提交
50
// xxx.ets
Z
zengyawen 已提交
51 52 53 54
@Entry
@Component
struct CircleExample {
  build() {
E
ester.zhou 已提交
55
    Column({ space: 10 }) {
Z
zengyawen 已提交
56 57
      // Draw a circle whose diameter is 150.
      Circle({ width: 150, height: 150 })
58
      // Draw a circle whose diameter is 150 and stroke color is red. (If the width and height values are different, the smaller value will be used as the diameter.)
E
ester.zhou 已提交
59 60 61 62 63 64 65 66
      Circle()
        .width(150)
        .height(200)
        .fillOpacity(0)
        .strokeWidth(3)
        .stroke(Color.Red)
        .strokeDashArray([1, 2])
    }.width('100%')
Z
zengyawen 已提交
67 68 69 70
  }
}
```

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