openharmony 鸿蒙 js-apis-arkui-shape

2025-06-12 浏览 (1)

@ohos.arkui.shape (Shape)

The shape module provides clipShape and maskShape APIs to allow you to pass in various shapes.

NOTE

The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.

You can preview how this component looks on a real device, but not in DevEco Studio Previewer.

Modules to Import

import { CircleShape, EllipseShape, PathShape, RectShape } from "@kit.ArkUI";

CircleShape

Represents a circle shape used in the clipShape and maskShape APIs.

Widget capability: This API can be used in ArkTS widgets since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

constructor

constructor(options?: ShapeSize)

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
optionsShapeSizeNoSize of the shape.

This API inherits from BaseShape.

EllipseShape

Represents an ellipse shape used in the clipShape and maskShape APIs.

Widget capability: This API can be used in ArkTS widgets since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

constructor

constructor(options?: ShapeSize)

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
optionsShapeSizeNoSize of the shape.

This API inherits from BaseShape.

PathShape

Represents a path used in the clipShape and maskShape APIs.

Widget capability: This API can be used in ArkTS widgets since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

constructor

constructor(options?: PathShapeOptions)

System capability: SystemCapability.ArkUI.ArkUI.Full

Atomic service API: This API can be used in atomic services since API version 12.

Widget capability: This API can be used in ArkTS widgets since API version 12.

NameTypeMandatoryDescription
optionsPathShapeOptionsNoPath parameters.

This API inherits from CommonShapeMethod.

commands

commands(commands: string): PathShape

Sets the path drawing commands.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
commandsstringYesPath drawing commands.

RectShape

Represents a rectangle shape used in the clipShape and maskShape APIs.

Widget capability: This API can be used in ArkTS widgets since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

constructor

constructor(options?: RectShapeOptions|RoundRectShapeOptions)

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
optionsRectShapeOptions | RoundRectShapeOptionsNoRectangle parameters.

This API inherits from BaseShape.

radiusWidth

radiusWidth(rWidth: number|string): RectShape

Sets the radius width of the rectangle border corners.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
rWidthnumber | stringYesRadius width of the rectangle border corners.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.

radiusHeight

radiusHeight(rHeight: number|string): RectShape

Sets the radius height of the rectangle border corners.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
rHeightnumber | stringYesRadius height of the rectangle border corners.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.

radius

radius(radius: number|string|Array<number | string>): RectShape

Sets the radius of the rectangle border corners.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
radiusnumber | string | Array<number | string>YesRadius of the rectangle border corners. When an array is provided, it should contain exactly four elements, corresponding to the radius of the upper left, upper right, lower left, and lower right corners of the rectangle, respectively. If more than four elements are contained, only the first four are accepted.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.

ShapeSize

Describes the size of a shape.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
widthnumber | stringNoWidth of the shape.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.
heightnumber | stringNoHeight of the shape.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.

PathShapeOptions

Represents the parameter of the constructor used to create a PathShape object.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
commandsstringNoPath drawing commands. For details, see commands.

RectShapeOptions

Represents the parameter of the constructor used to create a RectShape object.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

This API inherits from ShapeSize.

NameTypeMandatoryDescription
radiusnumber | string | Array<number | string>NoRadius of the rectangle border corners.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.

RoundRectShapeOptions

Represents the parameter of the constructor used to create a RectShape object with rounded corners.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

This API inherits from ShapeSize.

NameTypeMandatoryDescription
radiusWidthnumber | stringNoRadius width of the rectangle border corners.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.
radiusHeightnumber | stringNoRadius height of the rectangle border corners.
If the type is number, the value range is [0, +∞). If the type is string, the value represents a length.

BaseShape

Widget capability: This API can be used in ArkTS widgets since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

This API inherits from CommonShapeMethod.

width

width(width: Length): T

Sets the width of a shape.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
widthLengthYesWidth of the shape.

height

height(height: Length): T

Sets the height of a shape.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
heightLengthYesHeight of the shape.

size

size(size: SizeOptions): T

Sets the size of a shape.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
sizeSizeOptionsYesSize of the shape.

CommonShapeMethod

Widget capability: This API can be used in ArkTS widgets since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

offset

offset(offset: Position): T

Sets the coordinate offset relative to the component's layout position.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
offsetPositionYesCoordinate offset relative to the component's layout position.

fill

fill(color: ResourceColor): T

Sets the fill color of this shape, which determines its opacity, with black representing full transparency and white representing full opacity.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
colorResourceColorYesFill color of the shape, which represents the opacity of the fill area. The black color indicates full transparency, while white indicates full opacity.

position

position(position: Position): T

Sets the position of a shape.

Widget capability: This API can be used in ArkTS widgets since API version 12.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
positionPositionYesPosition of the shape.

Example

import { CircleShape, EllipseShape, PathShape, RectShape } from "@kit.ArkUI";

@Entry
@Component
struct ShapeExample {
  build() {
    Column({ space: 15 }) {
      Text('CircleShape, position').fontSize(20).width('75%').fontColor('#DCDCDC')
      Image($r('app.media.startIcon'))
        .clipShape(new CircleShape({ width: '280px', height: '280px' }).position({ x: '20px', y: '20px' }))
        .width('500px').height('280px')

      Text('EllipseShape, offset').fontSize(20).width('75%').fontColor('#DCDCDC')
      Image($r('app.media.startIcon'))
        .clipShape(new EllipseShape({ width: '350px', height: '280px' }).offset({ x: '10px', y: '10px' }))
        .width('500px').height('280px')

      Text('PathShape, fill').fontSize(20).width('75%').fontColor('#DCDCDC')
      Image($r('app.media.startIcon'))
        .maskShape(new PathShape().commands('M100 0 L200 240 L0 240 Z').fill(Color.Red))
        .width('500px').height('280px')
    
      Text('RectShape, width, height, fill').fontSize(20).width('75%').fontColor('#DCDCDC')
      Image($r('app.media.startIcon'))
        .maskShape(new RectShape().width('350px').height('280px').fill(Color.Red))
        .width('500px').height('280px')
    }
    .width('100%')
    .margin({ top: 15 })
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkUI

harmony 鸿蒙ARKUI_TextPickerCascadeRangeContent

harmony 鸿蒙ARKUI_TextPickerRangeContent

harmony 鸿蒙ArkUI_AnimateCompleteCallback

harmony 鸿蒙ArkUI_AttributeItem

harmony 鸿蒙ArkUI_ColorStop

harmony 鸿蒙ArkUI_ContextCallback

harmony 鸿蒙ArkUI_EventModule

harmony 鸿蒙ArkUI_ExpectedFrameRateRange

harmony 鸿蒙ArkUI_IntOffset

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/9QoTtc