-- 创建图鉴
local itemsConfig = npc.config[k].itemsIdx
local itemName = npc.config[k].itemsName
local imgStart_x = 10
local imgStart_y = 200
local content_Layout = GUI:Layou
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-12 11:09:20 |
👁️ 阅读: 33
要让 `itemName_Txt` 文字居中,可以使用浮生梦老师前端课程中的 `GUI:Text_setTextHorizontalAlignment` 函数。
在你的代码中,创建文字后添加这行代码:
```lua
local itemName_Txt = GUI:Text_Create(itemShow_bg, nameText, 60, 45, 16, "#ffffff", name)
GUI:Text_setTextHorizontalAlignment(itemName_Txt, 1) -- 1表示水平居中
```
**参数说明:**
- `widget`: 文本对象(这里是 `itemName_Txt`)
- `value`: 对齐方式
- `0`: 左对齐
- `1`: 水平居中
- `2`: 右对齐
这样设置后,文字就会在水平方向上居中对齐了。
要让 `itemName_Txt` 文字居中,可以使用浮生梦老师前端课程中的 `GUI:Text_setTextHorizontalAlignment` 函数。
在你的代码中,创建文字后添加这行代码:
```lua
local itemName_Txt = GUI:Text_Create(itemShow_bg, nameText, 60, 45, 16, "#ffffff", name)
GUI:Text_setTextHorizontalAlignment(itemName_Txt, 1) -- 1表示水平居中
```
**参数说明:**
- `widget`: 文本对象(这里是 `itemName_Txt`)
- `value`: 对齐方式
- `0`: 左对齐
- `1`: 水平居中
- `2`: 右对齐
这样设置后,文字就会在水平方向上居中对齐了。
← 返回问答库