# 外描边设置
设置组件外描边(outline)样式。外描边绘制在组件的外侧,不影响布局,不会占用组件本身大小。

> **说明:**
>
> 从API version 11开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## outline
outline(value: OutlineOptions): T
统一外描边样式设置接口。
**卡片能力:** 从API version 11开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------------------- | ---- | ------------ |
| value | [OutlineOptions](ts-types.md#outlineoptions11对象说明) | 是 | 外描边样式。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outline18+
outline(options: Optional\): T
统一外描边样式设置接口。与[outline](#outline)相比,options参数新增了对undefined类型的支持。
**卡片能力:** 从API version 18开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ----------------------------------------- | ---- | ---- |
| options | Optional\<[OutlineOptions](ts-types.md#outlineoptions11对象说明)> | 是 | 外描边样式。
当options的值为undefined时,恢复为无外边框效果。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## OutlineStyle11+枚举说明
外描边样式。
**卡片能力:** 从API version 11开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
| 名称 | 值 | 说明 |
| ------ | ------ | ----------------------- |
| SOLID | 0 | 显示为一条实线。 |
| DASHED | 1 | 显示为一系列短的方形虚线。 |
| DOTTED | 2 | 显示为一系列圆点,圆点半径为outlineWidth的一半。 |
## outlineStyle
outlineStyle(value: OutlineStyle | EdgeOutlineStyles): T
设置元素的外描边样式。
**卡片能力:** 从API version 11开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| value | [OutlineStyle](#outlinestyle11枚举说明) \| [EdgeOutlineStyles](ts-types.md#edgeoutlinestyles11对象说明) | 是 | 设置元素的外描边样式。
默认值:OutlineStyle.SOLID |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outlineStyle18+
outlineStyle(style: Optional\): T
设置元素的外描边样式。与[outlineStyle](#outlinestyle)相比,style参数新增了对undefined类型的支持。
**卡片能力:** 从API version 18开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| style | Optional\<[OutlineStyle](#outlinestyle11枚举说明) \| [EdgeOutlineStyles](ts-types.md#edgeoutlinestyles11对象说明)> | 是 | 设置元素的外描边样式。
默认值:OutlineStyle.SOLID
当style的值为undefined时,恢复为无外描边样式的效果。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outlineWidth
outlineWidth(value: Dimension | EdgeOutlineWidths): T
设置元素的外描边宽度。
**卡片能力:** 从API version 11开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| value | [Dimension](ts-types.md#dimension10) \| [EdgeOutlineWidths](ts-types.md#edgeoutlinewidths11对象说明) | 是 | 设置元素的外描边宽度,不支持百分比。
默认值:0。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outlineWidth18+
outlineWidth(width: Optional\): T
设置元素的外描边宽度。与[outlineWidth](#outlinewidth)相比,width参数新增了对undefined类型的支持。
**卡片能力:** 从API version 18开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| width | Optional\<[Dimension](ts-types.md#dimension10) \| [EdgeOutlineWidths](ts-types.md#edgeoutlinewidths11对象说明)> | 是 | 设置元素的外描边宽度,不支持百分比。
默认值:0。
当width的值为undefined时,恢复为无外描边宽度的效果。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outlineColor
outlineColor(value: ResourceColor | EdgeColors | LocalizedEdgeColors): T
设置元素的外描边颜色。
**卡片能力:** 从API version 11开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------ |
| value | [ResourceColor](ts-types.md#resourcecolor) \| [EdgeColors](ts-types.md#edgecolors9) \| [LocalizedEdgeColors](ts-types.md#localizededgecolors12)12+ | 是 | 设置元素的外描边颜色。
默认值:Color.Black |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outlineColor18+
outlineColor(color: Optional\): T
设置元素的外描边颜色。与[outlineColor](#outlinecolor)相比,color参数新增了对undefined类型的支持。
**卡片能力:** 从API version 18开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| color | Optional\<[ResourceColor](ts-types.md#resourcecolor) \| [EdgeColors](ts-types.md#edgecolors9) \| [LocalizedEdgeColors](ts-types.md#localizededgecolors12)> | 是 | 设置元素的外描边颜色。
默认值:Color.Black
当color的值为undefined时,恢复为描边颜色为Color.Black的效果。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outlineRadius
outlineRadius(value: Dimension | OutlineRadiuses): T
设置元素的外描边圆角半径。
**卡片能力:** 从API version 11开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| value | [Dimension](ts-types.md#dimension10) \| [OutlineRadiuses](ts-types.md#outlineradiuses11对象说明) | 是 | 设置元素的外描边圆角半径,不支持百分比。
默认值:0。
最大生效值:组件width/2 + outlineWidth或组件height/2 + outlineWidth。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## outlineRadius18+
outlineRadius(radius: Optional\): T
设置元素的外描边圆角半径。与[outlineRadius](#outlineradius)相比,radius参数新增了对undefined类型的支持。
**卡片能力:** 从API version 18开始,该接口支持在ArkTS卡片中使用。
**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
**系统能力:** SystemCapability.ArkUI.ArkUI.Full
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| radius | Optional\<[Dimension](ts-types.md#dimension10) \| [OutlineRadiuses](ts-types.md#outlineradiuses11对象说明)> | 是 | 设置元素的外描边圆角半径,不支持百分比。
默认值:0。
最大生效值:组件width/2 + outlineWidth或组件height/2 + outlineWidth。
当radius的值为undefined时,恢复为外描边圆角半径为0的效果。 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------------------ |
| T | 返回当前组件。 |
## 示例
### 示例1(使用外描边属性)
该示例主要演示如何通过outline来实现组件外描边。
```ts
// xxx.ets
@Entry
@Component
struct OutlineExample {
build() {
Column() {
Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
// 线段
Text('DASHED')
.backgroundColor(Color.Pink)
.outlineStyle(OutlineStyle.DASHED).outlineWidth(5).outlineColor(0xAFEEEE).outlineRadius(10)
.width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
// 点线
Text('DOTTED')
.backgroundColor(Color.Pink)
.outline({ width: 5, color: 0x317AF7, radius: 10, style: OutlineStyle.DOTTED })
.width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
}.width('100%').height(150)
Text('.outline')
.backgroundColor(Color.Pink)
.fontSize(50)
.width(300)
.height(300)
.outline({
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: OutlineStyle.DOTTED,
right: OutlineStyle.DOTTED,
top: OutlineStyle.SOLID,
bottom: OutlineStyle.DASHED
}
}).textAlign(TextAlign.Center)
}
}
}
```

### 示例2(使用LocalizedEdgeColors类型)
该示例将outline属性中的color属性值设置为LocalizedEdgeColors类型。
```ts
// xxx.ets
@Entry
@Component
struct OutlineExample {
build() {
Column() {
Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
// 线段
Text('DASHED')
.backgroundColor(Color.Pink)
.outlineStyle(OutlineStyle.DASHED).outlineWidth(5).outlineColor(0xAFEEEE).outlineRadius(10)
.width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
// 点线
Text('DOTTED')
.backgroundColor(Color.Pink)
.outline({ width: 5, color: 0x317AF7, radius: 10, style: OutlineStyle.DOTTED })
.width(120).height(120).textAlign(TextAlign.Center).fontSize(16)
}.width('100%').height(150)
Text('.outline')
.backgroundColor(Color.Pink)
.fontSize(50)
.width(300)
.height(300)
.outline({
width: { left: 3, right: 6, top: 10, bottom: 15 },
color: { start: '#e3bbbb', end: Color.Blue, top: Color.Red, bottom: Color.Green },
radius: { topLeft: 10, topRight: 20, bottomLeft: 40, bottomRight: 80 },
style: {
left: OutlineStyle.DOTTED,
right: OutlineStyle.DOTTED,
top: OutlineStyle.SOLID,
bottom: OutlineStyle.DASHED
}
}).textAlign(TextAlign.Center)
}
}
}
```
从左至右显示语言示例图

从右至左显示语言示例图
