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

T
explain  
tianyu 已提交
3 4
 用于绘制圆形的组件。 

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

Z
zengyawen 已提交
9 10

## 子组件
Z
zengyawen 已提交
11 12 13



Z
zengyawen 已提交
14 15 16

## 接口

L
luoying_ace_admin 已提交
17
Circle(options?: {width?: string | number, height?: string | number})
Z
zengyawen 已提交
18

Y
yamila 已提交
19 20 21 22 23 24
**参数:**

| 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- |
| width | string \| number | 否 | 宽度。<br>默认值:0 |
| height | string \| number | 否 | 高度。<br>默认值:0 |
Z
zengyawen 已提交
25 26 27

## 属性

L
luoying_ace_admin 已提交
28
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
T
firstt  
tianyu 已提交
29

Y
yamila 已提交
30 31 32 33 34 35 36 37 38 39
| 名称 | 类型 | 描述 |
| -------- | -------- | -------- |
| fill | [ResourceColor](ts-types.md) | 设置填充区域颜色。<br>默认值:Color.Black |
| fillOpacity | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource类型) | 设置填充区域透明度。<br>默认值:1 |
| stroke | [ResourceColor](ts-types.md) | 设置边框颜色,不设置时,默认没有边框。 |
| strokeDashArray | Array&lt;Length&gt; | 设置边框间隙。<br>默认值:[] |
| strokeDashOffset | number&nbsp;\|&nbsp;string  | 边框绘制起点的偏移量。<br>默认值:0 |
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | 设置边框端点绘制样式。<br>默认值:LineCapStyle.Butt |
| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | 设置边框拐角绘制样式。<br>默认值:LineJoinStyle.Miter |
| strokeMiterLimit | number&nbsp;\|&nbsp;string | 设置锐角绘制成斜角的极限值。<br>默认值:4<br/>**说明:**<br/>Circle组件无法设置锐角图形,该属性设置无效。 |
Y
yamila 已提交
40
| strokeOpacity | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource类型) | 设置边框透明度。<br>默认值:1<br/>**说明:**<br/>该属性的取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0。 |
Y
yamila 已提交
41 42
| strokeWidth | Length | 设置边框宽度。<br>默认值:1 |
| antiAlias | boolean | 是否开启抗锯齿效果。<br>默认值:true |
Z
zengyawen 已提交
43 44 45


## 示例
Z
zengyawen 已提交
46

H
geshi  
HelloCrease 已提交
47 48
```ts
// xxx.ets
Z
zengyawen 已提交
49 50 51 52
@Entry
@Component
struct CircleExample {
  build() {
53
    Column({ space: 10 }) {
Z
zengyawen 已提交
54 55
      // 绘制一个直径为150的圆
      Circle({ width: 150, height: 150 })
56 57 58 59 60 61 62 63 64
      // 绘制一个直径为150、线条为红色虚线的圆环(宽高设置不一致时以短边为直径)
      Circle()
        .width(150)
        .height(200)
        .fillOpacity(0)
        .strokeWidth(3)
        .stroke(Color.Red)
        .strokeDashArray([1, 2])
    }.width('100%')
Z
zengyawen 已提交
65 66 67 68
  }
}
```

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