PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TextXAlignment

TextButton

TextXAlignment

TextXAlignment determines the horizontal alignment (X-axis) of text rendered within a UI element’s space. It functions similarly to the CSS text-align property, with left, right and center values (there is no justify option). For Left and Right, text is rendered such that the left/right text bounds just touch the edge of the UI element rectangle. For Center, each line of text is centered on the very center of the UI element rectangle.

This property is used in conjunction with TextButton/TextYAlignment to fully determine text alignment on both axes. This property won’t affect the read-only properties TextButton/TextBounds and TextButton/TextFits.


Code Samples


Text Alignment

This code sample shows all the different text alignment combinations by iterating over each enum item. It is meant to be placed within a TextLabel, TextButton or TextBox.

-- Paste this in a LocalScript within a TextLabel/TextButton/TextBox
local textLabel = script.Parent

local function setAlignment(xAlign, yAlign)
	textLabel.TextXAlignment = xAlign
	textLabel.TextYAlignment = yAlign
	textLabel.Text = xAlign.Name .. " + " .. yAlign.Name
end

while true do
	-- Iterate over both TextXAlignment and TextYAlignment enum items
	for j, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
		for i, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
			setAlignment(xAlign, yAlign)
			wait(1)
		end
	end
end