浮層

2024-01-22 16:11 更新

設(shè)置組件的遮罩文本。

說明

從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨標(biāo)記該內(nèi)容的起始版本。

屬性

名稱

參數(shù)類型

默認(rèn)值

描述

overlay

value: string,

options?: {

align?: Alignment,

offset?: {x?: number, y?: number}

}

{

align: Alignment.TopStart,

offset: { x: 0, y: 0}

}

在當(dāng)前組件上,增加遮罩文本。

value: 遮罩文本內(nèi)容。

options: 文本定位,align設(shè)置文本相對于組件的方位,offset為文本基于自身左上角的偏移量。文本默認(rèn)處于組件左上角。

兩者都設(shè)置時效果重疊,文本相對于組件方位定位后再基于當(dāng)前位置文本的左上角進(jìn)行偏移。

從API version 9開始,該接口支持在ArkTS卡片中使用。

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct OverlayExample {
  5. build() {
  6. Column() {
  7. Column() {
  8. Text('floating layer')
  9. .fontSize(12).fontColor(0xCCCCCC).maxLines(1)
  10. Column() {
  11. Image($r('app.media.img'))
  12. .width(240).height(240)
  13. .overlay("Winter is a beautiful season, especially when it snows.", {
  14. align: Alignment.Bottom,
  15. offset: { x: 0, y: -15 }
  16. })
  17. }.border({ color: Color.Black, width: 2 })
  18. }.width('100%')
  19. }.padding({ top: 20 })
  20. }
  21. }

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號