Working on the UI which generates subcategories for each category. However, some subcategories have longer names (10 chars) compared to some other ones (4-5 chars), ruining the aesthetic and leaving some TextBoxes separated unevenly.
You can use the TextFits property to detect when the text fits inside the TextLabel:
local label = script.Parent.TextLabel
function ScaleText(textObject, offset)
if not textObject.TextFits then
repeat
textObject.TextSize -= 1
until textObject.TextFits
end
textObject.TextSize -= offset or 0
end
ScaleText(label, 5)
local UI = script.Parent --a screen UI
local label = UI.TextLabel
label.TextWrapped = false --must be set to false for the actual text size
local ScreenSize = UI.AbsoluteSize
local textOffset = label.TextBounds
local textScale = UDim2.fromScale(textOffset.X/ScreenSize.X, textOffset.Y/ScreenSize.Y)
label.Size = textScale+UDim2.fromScale(0.02, 0.02) --ExactSize+some offset
I assume the issue is related to button.TextWrapped = true showing you false results.
Basically, what your script does is, it still messes up the sizing and makes it extremely small although the text shows properly, but I can’t have the TextScaled set to off; I want this to match other device resolutions.