Skip to main content
版本:v3

widget.setProperty(propertyId, val)

设置 UI 控件属性。

类型

(propertyId: string, val: any) => void

参数

参数说明类型
propertyId属性 idPropertyId
val设置值(当 property 为 hmUI.prop.MORE 时, val 与 createWidget 的 option 用法一致,可设置多个参数)any

PropertyId

列举控件通用支持的属性

属性说明类型
x控件 x 坐标number
y控件 y 坐标number
w控件显示宽度number
h控件显示高度number
VISIBLE控件是否可见,true 为可见、false 不可见,该属性不支持 setProperty(hmUI.prop.MORE, {}),只支持 setProperty 单独设置 VISIBLE 属性boolean

代码示例

// 设置 widegt 隐藏/显示
const button = hmUI.createWidget(hmUI.widget.BUTTON, Param)
button.setProperty(hmUI.prop.VISIBLE, false)

const text = hmUI.createWidget(hmUI.widget.TEXT, Param)
text.setProperty(hmUI.prop.MORE, {
x: 0,
y: 0,
w: 200,
h: 200,
text: 'hello',
color: 0x34e073,
align_h: hmUI.align.LEFT
})