How to expand a scrolling frame to fit the items inside

How can I change the canvas size of a scrolling frame to fit the elements inside? I DO NOT want to use a UIGridLayout as I will be stuck to only a certain size. I would like it to be easily changeable as the elements inside are always changing sizes.

(If there any info you need, feel free to ask me :smile:)

1 Like

Are you using UIListLayout? If not, how are you organizing the elements?

1 Like

I am using a UIListLayout as they are easier to control the list.

1 Like

Sorry that I wasted anyone’s time, but as soon as I posted this topic, I found the solution. You can get the AbsoluteCanvas size from the list layout, to change the canvas size

ScrollingFrame.CanvasSize = UIListLayout.AbsoluteContentSize
1 Like

Here’s a script to size the scrollingframe correctly:

local ScrollingFrame = --ScrollingFrame
local UIListLayout = --UiListLayout

ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, UIListLayout.AbsoluteContentSize.Y)

UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
	ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, UIListLayout.AbsoluteContentSize.Y)
end)

4 Likes

Ah ok didn’t see this when replying, good luck anyways!

1 Like

Thank you for this - however how would I do this if my Scrolling frame and elements inside that frame are sized using scale rather than offset?

Use automatic canvas size set to the axis you want to scale on (xy in your case) then set the canvas size to 0,0,0,0