ts-universal-attributes-border-image.md 4.1 KB
Newer Older
E
ester.zhou 已提交
1
# Border Image
E
ester.zhou 已提交
2

E
ester.zhou 已提交
3
You can draw an image around a component.
E
ester.zhou 已提交
4

E
ester.zhou 已提交
5 6
>  **NOTE**
>
E
ester.zhou 已提交
7
>  The APIs of this module are supported since API version 9. Updates will be marked with a superscript to indicate their earliest API version.
E
ester.zhou 已提交
8 9 10

## Attributes

E
ester.zhou 已提交
11 12 13
| Name         | Type                                    | Description                                    |
| ----------- | ---------------------------------------- | -------------------------------------- |
| borderImage | [BorderImageOption](#borderimageoption) | Border image or border gradient.<br>This API is supported in ArkTS widgets.|
E
ester.zhou 已提交
14

E
ester.zhou 已提交
15
## BorderImageOption
E
ester.zhou 已提交
16

E
ester.zhou 已提交
17 18
This API is supported in ArkTS widgets.

E
ester.zhou 已提交
19 20 21 22 23 24 25 26
| Name    | Type                                      | Description                                      |
| ------ | ---------------------------------------- | ---------------------------------------- |
| source | string \| [Resource](ts-types.md#resource) \| [linearGradient](ts-universal-attributes-gradient-color.md) | Source or gradient color of the border image.<br>**NOTE**<br>The border image source applies only to container components, such as **\<Row>**, **\<Column>**, and **\<Flex>**.|
| slice  | [Length](ts-types.md#length) \| [EdgeWidths](ts-types.md#edgewidths9) | Slice width of the border image.<br>Default value: **0**                   |
| width  | [Length](ts-types.md#length) \| [EdgeWidths](ts-types.md#edgewidths9) | Width of the border image.<br>Default value: **0**                     |
| outset | [Length](ts-types.md#length) \| [EdgeWidths](ts-types.md#edgewidths9) | Amount by which the border image is extended beyond the border box.<br>Default value: **0**                 |
| repeat | [RepeatMode](#repeatmode)            | Repeat mode of the border image.<br>Default value: **RepeatMode.Stretch** |
| fill   | boolean                                  | Whether to fill the center of the border image.<br>Default value: **false**               |
E
ester.zhou 已提交
27 28 29

## RepeatMode

E
ester.zhou 已提交
30 31
This API is supported in ArkTS widgets.

E
ester.zhou 已提交
32 33 34 35 36 37
| Name     | Description                                 |
| ------- | ----------------------------------- |
| Repeat  | The source image's slices are tiled. Tiles beyond the border box will be clipped.         |
| Stretch | The source image's slices stretched to fill the border box.               |
| Round   | The source image's slices are tiled to fill the border box. Tiles may be compressed when needed.|
| Space   | The source image's slices are tiled to fill the border box. Extra space will be filled in between tiles.  |
E
ester.zhou 已提交
38

E
ester.zhou 已提交
39 40
## Example

E
ester.zhou 已提交
41 42 43
### Example 1


E
ester.zhou 已提交
44 45 46 47 48 49 50 51
```ts
// xxx.ets
@Entry
@Component
struct Index {
  build() {
    Row() {
      Column() {
E
ester.zhou 已提交
52
        Text('This is gradient color.').textAlign(TextAlign.Center).height(50).width(200)
E
ester.zhou 已提交
53
          .borderImage({
E
ester.zhou 已提交
54 55 56 57 58 59 60 61
            source: {
              angle: 90,
              direction: GradientDirection.Left,
              colors: [[0xAEE1E1, 0.0], [0xD3E0DC, 0.3], [0xFCD1D1, 1.0]]
            },
            slice: { top: 10, bottom: 10, left: 10, right: 10 },
            width: { top: "10px", bottom: "10px", left: "10px", right: "10px" },
            repeat: RepeatMode.Stretch,
E
ester.zhou 已提交
62
            fill: false
E
ester.zhou 已提交
63
          })
E
ester.zhou 已提交
64 65 66 67 68 69 70 71
      }
      .width('100%')
    }
    .height('100%')
  }
}
```

E
ester.zhou 已提交
72
![en-us_image_borderImageGradient](figures/borderImageGradient.png)
E
ester.zhou 已提交
73

E
ester.zhou 已提交
74
### Example 2
E
ester.zhou 已提交
75 76 77 78 79 80

```ts
// xxx.ets
@Entry
@Component
struct Index {
E
ester.zhou 已提交
81 82
  @State outSetValue: number = 40

E
ester.zhou 已提交
83 84 85
  build() {
    Row() {
      Column() {
E
ester.zhou 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
        Row() {
          Text('This is borderImage.').textAlign(TextAlign.Center).fontSize(50)
        }
        .borderImage({
          source: $r('app.media.icon'),
          slice: `${this.outSetValue}%`,
          width: `${this.outSetValue}px`,
          outset: '5px',
          repeat: RepeatMode.Repeat,
          fill: false
        })

        Slider({
          value: this.outSetValue,
          min: 0,
          max: 100,
          style: SliderStyle.OutSet
        })
          .margin({ top: 30 })
          .onChange((value: number, mode: SliderChangeMode) => {
            this.outSetValue = value
            console.info('value:' + value + 'mode:' + mode.toString())
E
ester.zhou 已提交
108
          })
E
ester.zhou 已提交
109 110 111 112 113 114 115 116
      }
      .width('100%')
    }
    .height('100%')
  }
}
```

E
ester.zhou 已提交
117
![zh-cn_image_borderImage](figures/borderImage.gif)