AspectRatioConstraint making spaces

Hey, I want to create a row of squares. Basically like this but it should be squares.


When I use the aspectratioconstraint they are becoming squares (I use scale) but then there is a weird spacing between each button and I dont know why.

This is my code:

local buttonCount = 15  
local frameSize = UDim2.new(1, 0, 1, 0) 
local buttonSize = UDim2.new(1 / buttonCount, 0, 1/buttonCount, 0) 



local gridLayout = Instance.new("UIGridLayout")
gridLayout.Parent = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
gridLayout.CellPadding = UDim2.new(0, 0, 0, 0)  
gridLayout.CellSize = buttonSize


for i = 1, buttonCount,1 do
	local button = Instance.new("TextButton")
	local ratio = Instance.new("UIAspectRatioConstraint")
	button.Parent = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
	button.Text = ""
	ratio.AspectRatio = 1
	ratio.Parent = button
	ratio.DominantAxis = "Height"
	ratio.AspectType = Enum.AspectType.ScaleWithParentSize

	button.TextColor3 = Color3.new(1, 1, 1)
	button.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)

end

I think it happens because my original buttonWidth is being decreased by the Constraint so there is an empty space. But how do I get rid of it?

Try setting the DominantAxis to width instead of height. This will change the height of the buttons instead of the width, removing the gaps.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.