openharmony 鸿蒙 ts-universal-attributes-border

2025-06-12 浏览 (1)

Border

The border attributes are used to set border styles for components.

NOTE

The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.

border

border(value: BorderOptions)

Sets the border.

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

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueBorderOptionsYesUnified border style.
NOTE
The default value is 0, indicating that the border is not displayed.
The border of a component is displayed above the content of its child components since API version 9.

borderStyle

borderStyle(value: BorderStyle|EdgeStyles)

Sets the border style.

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

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueBorderStyle |EdgeStyles9+YesBorder style.
Default value: BorderStyle.Solid

borderWidth

borderWidth(value: Length|EdgeWidths|LocalizedEdgeWidths)

Sets the border width.

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

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueLength |EdgeWidths9+ |LocalizedEdgeWidths12+YesBorder width. Percentage values are not supported.

borderColor

borderColor(value: ResourceColor|EdgeColors|LocalizedEdgeColors)

Sets the border color.

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

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueResourceColor |EdgeColors9+ |LocalizedEdgeColors12+YesBorder color.
Default value: Color.Black

borderRadius

borderRadius(value: Length|BorderRadiuses|LocalizedBorderRadiuses)

Sets the radius of the border rounded corners. The radius is restricted by the component size. The maximum value is half of the component width or height.

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

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

NameTypeMandatoryDescription
valueLength |BorderRadiuses9+ |LocalizedBorderRadiuses12+YesRadius of the border rounded corners. The value can be expressed as a percentage of the component's width.

BorderOptions

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

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

NameTypeMandatoryDescription
widthLength |EdgeWidths9+ |LocalizedEdgeWidths12+NoBorder width.
colorResourceColor |EdgeColors9+ |LocalizedEdgeColors12+NoBorder color.
radiusLength |BorderRadiuses9+ |LocalizedBorderRadiuses12+NoRadius of the border rounded corners.
styleBorderStyle |EdgeStyles9+NoSets the border.
dashGap12+LengthMetrics |EdgeWidths |LocalizedEdgeWidthsNoGap between dashed line segments. It takes effect when the border style is set to dashed.
Percentage values are not supported.
dashWidth12+LengthMetrics |EdgeWidths |LocalizedEdgeWidthsNoWidth of dashed line segments. It takes effect when the border style is set to dashed.
Percentage values are not supported.

EdgeWidths9+

To reference this object, at least one parameter must be passed.

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

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

NameTypeMandatoryDescription
leftLengthNoWidth of the left border.
rightLengthNoWidth of the right border.
topLengthNoWidth of the top border.
bottomLengthNoWidth of the bottom border.

LocalizedEdgeWidths12+

Represents the edge widths in different directions of a component.

To reference this object, at least one parameter must be passed.

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

NameTypeMandatoryDescription
startLengthMetricsNoWidth of the left border.
Width of the right border for right-to-left scripts.
endLengthMetricsNoWidth of the right border.
Width of the left border for right-to-left scripts.
topLengthMetricsNoWidth of the top border.
bottomLengthMetricsNoWidth of the bottom border.

EdgeColors9+

To reference this object, at least one parameter must be passed.

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

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

NameTypeMandatoryDescription
leftResourceColorNoColor of the left border.
rightResourceColorNoColor of the right border.
topResourceColorNoColor of the top border.
bottomResourceColorNoColor of the bottom border.

LocalizedEdgeColors12+

Describes the edge colors of a component.

To reference this object, at least one parameter must be passed.

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.

NameTypeMandatoryDescription
startResourceColorNoColor of the left border.
Color of the right border for right-to-left scripts.
endResourceColorNoColor of the right border.
Color of the left border for right-to-left scripts.
topResourceColorNoColor of the top border.
bottomResourceColorNoColor of the bottom border.

BorderRadiuses9+

To reference this object, at least one parameter must be passed.

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

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

NameTypeMandatoryDescription
topLeftLengthNoRadius of the upper left rounded corner.
topRightLengthNoRadius of the upper right rounded corner.
bottomLeftLengthNoRadius of the lower left rounded corner.
bottomRightLengthNoRadius of the lower right rounded corner.

LocalizedBorderRadiuses12+

Describes the corner radius of a component's border.

To reference this object, at least one parameter must be passed.

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.

NameTypeMandatoryDescription
topStartLengthMetrics12+NoRadius of the upper left rounded corner.
Radius of the upper right rounded corner for right-to-left scripts.
topEndLengthMetrics12+NoRadius of the upper right rounded corner.
Radius of the upper left rounded corner for right-to-left scripts.
bottomStartLengthMetrics12+NoRadius of the lower left rounded corner.
Radius of the lower right rounded corner for right-to-left scripts.
bottomEndLengthMetrics12+NoRadius of the lower right rounded corner.
Radius of the lower left rounded corner for right-to-left scripts.

EdgeStyles9+

To reference this object, at least one parameter must be passed.

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

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

NameTypeMandatoryDescription
leftBorderStyleNoStyle of the left border.
rightBorderStyleNoStyle of the right border.
topBorderStyleNoStyle of the top border.
bottomBorderStyleNoStyle of the bottom border.

Example

Example 1

// xxx.ets
@Entry
@Component
struct BorderExample {
  build() {
    Column() {
      Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
        // Dashed border
        Text('dashed')
          .borderStyle(BorderStyle.Dashed).borderWidth(5).borderColor(0xAFEEEE).borderRadius(10)
          .width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
        // Dotted border
        Text('dotted')
          .border({ width: 5, color: 0x317AF7, radius: 10, style: BorderStyle.Dotted })
          .width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
      }.width('100%').height(150)

      Text('.border')
        .fontSize(50)
        .width(300)
        .height(300)
        .border({
          width: { left: 3, right: 6, top: 10, bottom: 15 },
          color: { left: '#e3bbbb', right: Color.Blue, top: Color.Red, bottom: Color.Green },
          radius: { topLeft: 10, topRight: 20, bottomLeft: 40, bottomRight: 80 },
          style: {
            left: BorderStyle.Dotted,
            right: BorderStyle.Dotted,
            top: BorderStyle.Solid,
            bottom: BorderStyle.Dashed
          }
        }).textAlign(TextAlign.Center)
    }
  }
}

en-us_image_0000001211898466

Example 2

// xxx.ets
// The width, radius, and color attributes of border use the LocalizedEdgeWidths and LocalizedEdgeColors types.

import { LengthMetrics } from '@kit.ArkUI';
@Entry
@Component
struct BorderExample {
  build() {
    Column() {
      Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
        // Dashed border
        Text('dashed')
          .borderStyle(BorderStyle.Dashed)
          .borderWidth(5)
          .borderColor(0xAFEEEE)
          .borderRadius(10)
          .width(120)
          .height(120)
          .textAlign(TextAlign.Center)
          .fontSize(16)
        // Dotted border
        Text('dotted')
          .border({ width: 5, color: 0x317AF7, radius: 10, style: BorderStyle.Dotted })
          .width(120)
          .height(120)
          .textAlign(TextAlign.Center)
          .fontSize(16)
      }.width('100%').height(150)

      Text('.border')
        .fontSize(50)
        .width(300)
        .height(300)
        .border({
          width: {
            start: LengthMetrics.vp(3),
            end: LengthMetrics.vp(6),
            top: LengthMetrics.vp(10),
            bottom: LengthMetrics.vp(15)
          },
          color: { start: '#e3bbbb', end: Color.Blue, top: Color.Red, bottom: Color.Green },
          radius: {
            topStart: LengthMetrics.vp(10),
            topEnd: LengthMetrics.vp(20),
            bottomStart: LengthMetrics.vp(40),
            bottomEnd: LengthMetrics.vp(80)
          },
          style: {
            left: BorderStyle.Dotted,
            right: BorderStyle.Dotted,
            top: BorderStyle.Solid,
            bottom: BorderStyle.Dashed
          }
        })
        .textAlign(TextAlign.Center)
    }
  }
}

The following shows how the example is represented with left-to-right scripts.

en-us_image_border_ltr

The following shows how the example is represented with right-to-left scripts.

en-us_image_border_rtl

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcButton

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙DownloadFileButton

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