一个 TextButton 在渲染方面与 TextLabel 相似,还有一个 GuiButton 的额外行为。
您可以通过设置 TextTransparency 为 1 来禁用文本渲染。这将导致一个简单的长方形,可用作按钮。
概要
属性
包含 TextButton.Text 中正确显示的内容的副本,该内容由 TextButton 渲染。
决定用于渲染文本的字体。
决定用于渲染文本的字体。
在 TextButton 中缩放文本行之间的间距。
设置是否应该将 TextButton 设置为 GuiBase2d.Localize 或不。
TextButton 可以显示的最大字母数量。
决定是否使用富文本格式来渲染 TextButton 的文本。
决定由 TextButton 渲染的字符串。
仅读属性,反映偏移中渲染文本的绝对大小。
决定渲染文本的颜色。
文本渲染的方向。
是否按钮的文本是否适合按钮的大小的 boolean 表示。
改变文本是否被调整以适合 TextButton 内。
决定抵消文本的行高度。
决定文本杆的颜色(轮廓)。
决定文本行的透明度(轮廓)。
决定渲染文本的透明度。
控制在 TextButton 中显示的文本的截断。
决定是否将文本包装到 TextButton 元素空间内的多个线上,减少多余的文本。
确定渲染文本的横向对齐。
确定渲染文本的垂直对齐。
决定是否当鼠标悬停或单击时,按钮会自动更改颜色。
当 被悬停时会播放的实例。
如果 true 在图形用户界面元素可见时,鼠标不会锁定,除非右键按钮向下。
一个当 HapticEffect 按下时会播放的实例,当 GuiButton 按下时。
一个指示对象是否已选择的 boolean 属性。
根据一列预定义风格设置 GuiButton 的风格。
决定这个 UI 元素是否沉没输入。
确定 GuiObject 的起始点,相对于其绝对尺寸。
决定是否基于子内容进行缩放。
决定 GuiObject 背景颜色。
决定 GuiObject 背景和边界的透明度。
决定 GuiObject 边框的颜色。
决定边界 GuiObject 是如何相对于其尺寸布置。
决定 GuiObject 边框的像素宽度。
决定是否描渲染父级 GUI 元素边界外的子元素 GuiObjects。
决定玩家的鼠标是否在 GuiObject 上被主动按下。
控制使用 GuiObject 与 UIGridStyleLayout 时的排序顺序。
设置当游戏手柄选择器向下移动时将选择的 GuiObject 。
设置当游戏手柄选择器移至左侧时将选择的 GuiObject 。
设置当游戏手柄选择器移至右侧时将选择的 GuiObject 。
设置当游戏手柄选择器向上移动时将选择的 GuiObject 。
确定 GuiObject 的像素和坐标位置。
决定旋转 GuiObject 的角度数。
确定是否可以由游戏手柄选择 GuiObject 。
覆盖用于游戏手柄的默认选择装饰。
游戏手柄 UI 选择选择的 GuiObjects 顺序。
决定 GuiObject 的像素和积分尺寸。
混合属性 BackgroundTransparency 和 TextTransparency 。
决定是否渲染 GuiObject 和其子孙。
决定 GuiObject 对其他人的相对渲染顺序。
方法
继承自GuiObject的方法- TweenPosition(endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
平滑地将图形用户界面移至新的 UDim2 。
- TweenSize(endSize : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
- TweenSizeAndPosition(endSize : UDim2,endPosition : UDim2,easingDirection : Enum.EasingDirection,easingStyle : Enum.EasingStyle,time : number,override : boolean,callback : function):boolean
平滑地将图形用户界面移至新的尺寸和位置。
活动
继承自GuiButton的活动当按钮激活时发火。
当用户的鼠标完全点击 GuiButton 时发生火焰。
当用户按下左键时,在 GuiButton 上按下左键时发生火焰。
当用户释放左鼠标按钮时,发生在 GuiButton 上。
当用户的鼠标完全右键单击 GuiButton 时发生火焰。
当用户按下鼠标右键向下在 GuiButton 上时,发生火焰。
当用户释放鼠标右键时,火焰从 GuiButton 上。
当用户开始通过人机界面设备(鼠标按钮向下、触摸开始、键盘按钮向下等)进行交互时,发射。
当用户通过人机界面设备(鼠标按钮向下、触摸开始、键盘按钮向下等)更改他们的互动方式时,发射。
当用户停止通过人机界面设备(鼠标按钮向下、触摸开始、键盘按钮向下等)进行交互时,发射。
当用户将鼠标移至图形用户界面元素时发生火焰。
当用户将鼠标移出 GUI 元素时发生火焰。
在用户移动鼠标时,无论它在哪个 GUI 元素内,都会发生火焰。
当用户滚动鼠标轮返回时,火焰当鼠标悬停在图形用户界面元素上。
当用户滚动鼠标轮时向前移动时,触发当鼠标悬停在图形用户界面元素上时。
在使用游戏手柄选择器时将 GuiObject 聚焦时发射。
当游戏手柄选择器停止关注 GuiObject 时发射。
当玩家开始、继续和停止长按 UI 元素时,发生火焰。
- TouchPan(touchPositions : Array,totalTranslation : Vector2,velocity : Vector2,state : Enum.UserInputState):RBXScriptSignal
当玩家在 UI 元素上移动手指时发生火焰。
- TouchPinch(touchPositions : Array,scale : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
当玩家使用界面元素上的两个手指执行捏或拉动动作时,发生火焰。
- TouchRotate(touchPositions : Array,rotation : number,velocity : number,state : Enum.UserInputState):RBXScriptSignal
当玩家使用界面元素上的两个手指执行旋转动作时,发生火焰。
当玩家在 UI 元素上执行滑动动作时发生火焰。
当玩家在 UI 元素上执行了点击动作时发生火焰。
- SelectionChanged(amISelected : boolean,previousSelection : GuiObject,newSelection : GuiObject):RBXScriptSignal
当游戏手柄选择移动到、离开或在连接的 或任何子手柄中更改时,发生火焰。
属性
ContentText
该属性提供了一个复制的 Text 包含正确被渲染的 TextButton 的内容。这对于消除用于 富文本 标记的样式标签有用;例如,当 RichText 启用时,ContentText 属性将显示用户看到的文本。
<th>文本</th><th>内容文本</th></tr></thead><tbody><tr><td><code>错误</code></td><td><b>你好,<br/> 世界!</b></td><td><b>你好,<br/> 世界!</b></td></tr><tr><td><code>真实</code></td><td><b>你好,<br/> 世界!</b></td><td>你好,世界!</td></tr></tbody>
富文本 |
---|
Font
该属性选择几个预定义字体之一,用于 TextButton 渲染其文本。一些字体具有粗体、斜体和/或浅色变体。
除了 Enum.Font.Legacy 字体外,每个字体都会渲染具有线高度等于 TextSize 属性的文本。
Enum.Font.Code 字体是唯一的单空间字体。它具有独特的属性,每个角色的宽度和高度比例为 1:2,每个角色的宽度大约是 TextSize 属性的一半。
该属性与 FontFace 属性保持同步。
代码示例
This code sample renders a list of all the available fonts.
local frame = script.Parent
-- Create a TextLabel displaying each font
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- Set the text properties
textLabel.Text = font.Name
textLabel.Font = font
-- Some rendering properties
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- Size the frame equal to the height of the text
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- Add to the parent frame
textLabel.Parent = frame
end
-- Layout the frames in a list (if they aren't already)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
FontFace
该属性与 Font 属性相似,但允许设置在 Enum.Font 中不存在的字体。
此属性与 Font 属性保持同步,使设置 FontFace 时,字体设置为相应的 Enum.Font 值或 Enum.Font.Unknown 如果没有匹配。
MaxVisibleGraphemes
该属性控制在 TextButton 上显示的最大字母数量 (或文本单位)。主要用作简单的方法来创建一个 打字机效果 ,其中字符一个接一个出现。
更改属性不会更改可见的字母的位置或大小;布局将被计算为如果所有字母都可见。
将属性设置为 -1 将限制禁用并显示 Text 的整体。
OpenTypeFeatures
OpenTypeFeaturesError
Text
该属性决定了 TextButton 渲染的文本内容。渲染到屏幕的字符串的视觉属性由 , , > , > , > 和 > 决定。
可以渲染不受 TextColor3 属性影响的表情符号,例如 🔒 和其他符号。这些可以粘贴到 和 对象以及 属性窗口内的字段。
该属性可能包含新行字符。相同,该属性可能包含一个标签字符,但它将以空格形式渲染。
代码示例
This code sample creates a fading banner for a TextLabel. It fades text out, chooses a random string (avoiding repetition), and fades back in.
local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"Welcome to my game!",
"Be sure to have fun!",
"Please give suggestions!",
"Be nice to other players!",
"Don't grief other players!",
"Check out the shop!",
"Tip: Don't die!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- Step 0: Fade out before doing anything
fadeOut:Play()
task.wait(tweenInfo.Time)
-- Step 1: pick content that wasn't the last displayed
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- Make sure we don't show the same thing next time
lastIndex = index
-- Step 2: show the content
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end
This code sample demonstrates emoji rendering using the Text property.
local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "I am feeling " .. mood .. "! " .. face
task.wait(1)
end
end
TextBounds
这个仅读取属性反映了渲染文本的绝对大小在偏移量中,这意味着如果你尝试将文本放入长方形,这个属性将反映出你需要在长方形中最小尺寸才能放置文本的最小尺寸。
使用 TextService:GetTextSize() , 你可以预测 TextBounds 将被给予什么字符串、Font 、TextSize 和框架大小。
TextColor3
该属性决定了 TextButton 元素渲染的所有文本的颜色。
代码示例
This code sample makes a TextLabel or TextButton count backwards from 10, setting the text color as it does so.
-- Place this code in a LocalScript within a TextLabel/TextButton
local textLabel = script.Parent
-- Some colors we'll use with TextColor3
local colorNormal = Color3.new(0, 0, 0) -- black
local colorSoon = Color3.new(1, 0.5, 0.5) -- red
local colorDone = Color3.new(0.5, 1, 0.5) -- green
-- Loop infinitely
while true do
-- Count backwards from 10 to 1
for i = 10, 1, -1 do
-- Set the text
textLabel.Text = "Time: " .. i
-- Set the color based on how much time is left
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "GO!"
textLabel.TextColor3 = colorDone
task.wait(2)
end
TextScaled
该属性决定是否将文本缩放以填充按钮的整个空间。启用时,TextSize被忽略,TextWrapped自动启用。此属性有用于在 BillboardGuis 内渲染文本元素。当此属性用于在屏幕上的用户界面时,可能有用使用 来限制可能的文本尺寸范围。
自动缩放
建议您避免使用 TextScaled 并调整用户界面以利用 AutomaticSize 属性。以下是两个属性之间的核心差异:
TextScaled 将内容(文本)缩放以容纳用户界面。如果没有仔细考虑,一些文本可能会因缩放太小而变得难以阅读。
AutomaticSize 将UI调整为适合内容的尺寸,同时保持一致的字体大小。了解更多信息,请参阅这里。
此外,建议您避免同时应用 AutomaticSize 和 TextScaled 以及同一 TextButton 。AutomaticSize 确定 GuiObject 可以使用的最大空间(在这种情况下是文本),而TextScaled 使用由 AutomaticSize 决定的可用空间来将字体大小缩放到最大字体大小(100),如果没有尺寸限制。
TextStrokeColor3
此属性设置渲染文本的stroke或轮廓颜色。与 TextStrokeTransparency 一起,它决定了文本杆的最终视觉外观。
作为一个强大的替代方案,支持颜色渐变,请参阅 UIStroke 。
TextStrokeTransparency
此属性设置渲染文本的stroke或轮廓透明度。与 TextStrokeColor3 一起,它决定了文本杆的最终视觉外观。
请注意,文本stroke是同一透明度的多个渲染,因此此属性实际上是四倍增加的。因此,建议将 TextStrokeTransparency 设置为范围内的值 0.75 到 1 的更多微妙效果。
作为一个强大的替代方案,支持颜色渐变,请参阅 UIStroke 。
TextWrapped
启用后,该属性将在 TextButton 元素空间内的多个线上渲染文本,以便 TextBounds 永远不会超过元素的 GuiBase2d.AbsoluteSize 。这可以通过将长条文本拆分为多个线来实现。
行间空格会被首选;如果一个长而未被分割的单词超出元素宽度,该单词将被分为多个线段。
如果进一步的行分割会导致文本( Y 组件的TextBounds)的垂直高度超过元素( Y 组件的GuiBase2d.AbsoluteSize)的垂直高度,那条线将不会被渲染。
TextXAlignment
该属性决定对象空间内渲染的文本的横向对齐。它与 TextYAlignment 结合使用,可以完全确定在两个轴上的文本对齐。
请注意,此属性不会影响 read-only 属性 TextBounds 和 TextFits 。
TextYAlignment
该属性决定对象空间内渲染的文本的垂直对齐。它与 TextXAlignment 结合使用,可以完全确定在两个轴上的文本对齐。
请注意,此属性不会影响 read-only 属性 TextBounds 和 TextFits 。