UITextInput
继承自:
描述
输入框组件。用于在UI中输入文本内容
属性
ColorQuad TitleColor |
|---|
| 文本颜色设置。控制输入框中显示文本的颜色,默认值为黑色(0,0,0,255) |
TextVAlignment TextVAlignment |
|---|
| 文本垂直对齐方式。默认值为顶部对齐 |
TextHAlignment TextHAlignment |
|---|
| 文本水平对齐方式。默认值为左对齐 |
int MaxLength |
|---|
| 最大输入文本长度限制。超过此长度的输入将被截断,默认值为18个字符 |
int FontSize |
|---|
| 文本字体大小。取值范围为1-120,默认值为18 |
string Title |
|---|
| 输入框文本内容 |
事件
SBXSignal Return () |
|---|
| 输入完成事件。当用户在输入框中完成输入操作(如按回车键或失去焦点)时触发此事件 |
代码示例
lua
local root = SandboxNode.new('UIRoot', game.WorkSpace)
local petNameText = SandboxNode.new('UITextInput', root)
petNameText.Name = "PetNameText"
petNameText.Size = Vector2.new(120, 50)
petNameText.Position = Vector2.new(400, 250)
--设置输入框背景颜色
petNameText.FillColor = ColorQuad.new(97, 151, 230, 255)
--设置文本上下对齐
petNameText.TextVAlignment = Enum.TextVAlignment.Center
--设置文本左右对齐
petNameText.TextHAlignment = Enum.TextHAlignment.Center
--设置输入内容
petNameText.Title = "宠物狼"
--设置输入文本最长长度
petNameText.MaxLength = 20
--设置输入文本字体大小
petNameText.FontSize = 25