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

Dynamic TextBox Size

Dynamic TextBox Size

Oct 01 2018, 2:23 AM PST

This code sample dynamically resizes a TextLabel, TextButton or TextBox to match the size of its TextBounds. Try changing the minimum width/height and pasting into a LocalScript in a TextBox.

local textBox = script.Parent

-- The smallest the TextBox will go
local minWidth, minHeight = 10, 10

-- Set alignment so our text doesn't wobble a bit while we type
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top

local function updateSize()
	textBox.Size = UDim2.new(
		0, math.max(minWidth, textBox.TextBounds.X),
		0, math.max(minHeight, textBox.TextBounds.Y)
	)
end

textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)