harmony 鸿蒙Border

2022-08-09 浏览 (1306)

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.

The border of a component is displayed above the content of its child components since API version 9.

Attributes

NameTypeDescription
border{
width?: Length |EdgeWidths9+,
color?: ResourceColor |EdgeColors9+,
radius?: Length |BorderRadiuses9+,
style?: BorderStyle |EdgeStyles9+
}
Unified border style.
- width: border width.
- color: border color.
- radius: radius of the rounded corner of the border.
- style: border style.
Since API version 9, this API is supported in ArkTS widgets.
borderStyleBorderStyle |EdgeStyles9+Border style.
Default value: BorderStyle.Solid
Since API version 9, this API is supported in ArkTS widgets.
borderWidthLength |EdgeWidths9+Border width. The percentage format is not supported.
Since API version 9, this API is supported in ArkTS widgets.
borderColorResourceColor |EdgeColors9+Border color.
Default value: Color.Black
Since API version 9, this API is supported in ArkTS widgets.
borderRadiusLength |BorderRadiuses9+Border radius. The percentage format is not supported.
Since API version 9, this API is supported in ArkTS widgets.

EdgeWidths9+

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

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

EdgeColors9+

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

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

BorderRadiuses9+

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

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.

EdgeStyles9+

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

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

Example

// 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

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkTS-based Declarative Development Paradigm

harmony 鸿蒙@ohos.multimedia.avCastPicker (AVCastPicker)

harmony 鸿蒙Property Animation

harmony 鸿蒙Enums

harmony 鸿蒙Blank

harmony 鸿蒙Button

harmony 鸿蒙CalendarPicker

harmony 鸿蒙Checkbox

harmony 鸿蒙CheckboxGroup

harmony 鸿蒙DataPanel

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