ts-universal-attributes-border.md 2.9 KB
Newer Older
Z
zengyawen 已提交
1 2
# 边框设置

H
geshi  
HelloCrease 已提交
3
>  **说明:**
4 5 6
>
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
>
C
caocan 已提交
7
> 从API Version 9开始,父节点的border显示在子节点内容之上。
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10 11

设置组件边框样式。

Z
zengyawen 已提交
12 13

## 权限列表
Z
zengyawen 已提交
14 15 16



Z
zengyawen 已提交
17 18 19 20 21 22

## 属性


| 名称 | 参数类型 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- |
23
| border | BorderOptions | - | 统一边框样式设置接口。 |
Z
zengyawen 已提交
24 25 26 27 28
| borderStyle | BorderStyle |  BorderStyle.Solid | 设置元素的边框样式。 |
| borderWidth | Length | 0 | 设置元素的边框宽度。 |
| borderColor | Color | - | 设置元素的边框颜色。 |
| borderRadius | Length | 0 | 设置元素的边框圆角半径。 |

29 30 31 32
- BorderOptions属性说明
  | 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 |
  | -------- | -------- | -------- | -------- | -------- |
  | width | [Length](../../ui/ts-types.md#长度类型) | 0 | 否 | 边框宽度。 |
33
  | color | [ResourceColor](../../ui/ts-types.md) | 'Black' | 否 | 边框颜色。 |
T
tianyu 已提交
34
  | radius | [Length](../../ui/ts-types.md#长度类型)\| EdgeRadiuses<sup>9+</sup> | 0 | 否 | 边框角度。 |
35 36
  | style | BorderStyle | BorderStyle.Solid | 否 | 边框样式。 |

Z
zengyawen 已提交
37

T
tianyu 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50
- EdgeRadiuses<sup>9+</sup>对象说明
  
  引用该对象时,至少传入一个参数。
  
  | 名称        | 参数类型 | 必填 | 默认值 | 描述             |
  | ----------- | -------- | ---- | ------ | ---------------- |
  | topLeft     | length   | 否   | 0      | 左上角圆角半径。 |
  | topRight    | length   | 否   | 0      | 右上角圆角半径。 |
  | bottomLeft  | length   | 否   | 0      | 左下角圆角半径。 |
  | bottomRight | length   | 否   | 0      | 右下角圆角半径。 |
  
  
  
Z
zengyawen 已提交
51
- BorderStyle枚举说明
T
tianyu 已提交
52 53
  
  | 名称 | 描述 |
Z
zengyawen 已提交
54
  | -------- | -------- |
T
tianyu 已提交
55 56 57
  | Dotted | 显示为一系列圆点,圆点半径为borderWidth的一半。 |
  | Dashed | 显示为一系列短的方形虚线。 |
  | Solid | 显示为一条实线。 |
Z
zengyawen 已提交
58 59 60


## 示例
Z
zengyawen 已提交
61

H
geshi  
HelloCrease 已提交
62 63
```ts
// xxx.ets
Z
zengyawen 已提交
64 65 66 67 68 69 70 71 72
@Entry
@Component
struct BorderExample {
  build() {
    Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
      // 线段
      Text('dashed')
        .borderStyle(BorderStyle.Dashed).borderWidth(5).borderColor(0xAFEEEE).borderRadius(10)
        .width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
T
tianyu 已提交
73 74 75 76
      Text('dashed')
        .borderStyle(BorderStyle.Dashed).borderWidth(5).borderColor(0xAFEEEE)
        .borderRadius({ topLeft: 10, topRight: 20, bottomLeft: 30, bottomRight: 60 })
        .width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
Z
zengyawen 已提交
77 78 79 80 81 82 83 84 85
      // 点线
      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)
  }
}
```

Z
zengyawen 已提交
86
![zh-cn_image_0000001219982705](figures/zh-cn_image_0000001219982705.gif)