Skip to main content
Version: v3

TEXT

text_sample

Text component for displaying text. Support setting text size, color and alignment.

Create UI widget

const text = hmUI.createWidget(hmUI.widget.TEXT, Param)

Type

Param: object

PropertiesDescriptionRequiredType
xThe x-axis coordinate of the component.YESnumber
yThe y-axis coordinate of the component.YESnumber
wThe width of the component.YESnumber
hThe height of the component.YESnumber
colorThe color of the text.NOnumber
align_hThe alignment of the horizontal axis (see ALIGN for values).NOALIGN
align_vAlignment of the vertical axis (see ALIGN for values).NOALIGN
textTextNOstring
text_sizeThe size of the font.NOnumber
text_styleText overlength handling, default is hmUI.text_style.NONE (see TEXT_STYLE for value).NOTEXT_STYLE
line_spaceRow spacing.NOnumber
char_spaceCharacter Spacing.NOnumber

ALIGN alignment

ValueDescription
hmUI.align.LEFTHorizontal axis-left aligned.
hmUI.align.RIGHTHorizontal axis-align right.
hmUI.align.CENTER_HHorizontal axis-centered.
hmUI.align.TOPVertical axis-top.
hmUI.align.BOTTOMVertical axis-bottommost.
hmUI.align.CENTER_VVertical axis-centered.

TEXT_STYLE Text layout

ValueDescription
hmUI.text_style.ELLIPSISSingle line overflow character display...
hmUI.text_style.NONEKeep scrolling.

Code example

Page({
build() {
const text = hmUI.createWidget(hmUI.widget.TEXT, {
x: 96,
y: 120,
w: 288,
h: 46,
color: 0xffffff,
text_size: 36,
align_h: hmUI.align.CENTER_H,
align_v: hmUI.align.CENTER_V,
text_style: hmUI.text_style.NONE,
text: 'HELLO ZEPPOS'
})

text.addEventListener(hmUI.event.CLICK_DOWN, (info) => {
text.setProperty(hmUI.prop.MORE, {
y: 200
})
})
}
})