One fairly basic approach depending on knowing the total number of buttons ahead of time and the gridFrame size being absolute.
Lua Code:
local gridFrame = CreateFrame("Frame", "DragFrame2", UIParent)
gridFrame:SetMovable(true)
gridFrame:EnableMouse(true)
gridFrame:RegisterForDrag("LeftButton")
gridFrame:SetScript("OnDragStart", gridFrame.StartMoving)
gridFrame:SetScript("OnDragStop", gridFrame.StopMovingOrSizing)
-- The code below makes the frame visible, and is not necessary to enable dragging.
gridFrame:SetPoint("CENTER"); gridFrame:SetWidth(300); gridFrame:SetHeight(300);
local gridFrameTexture = gridFrame:CreateTexture("ARTWORK");
gridFrameTexture:SetAllPoints();
gridFrameTexture:SetColorTexture(0.89,0.44,0.1, 0.5)
local last = gridFrame
local count = 8
local height = gridFrame:GetHeight()/count
local point = "TOPLEFT"
-- SubFrame
for i=1, count do
local subFrame = CreateFrame("Button", "subFrame"..i, gridFrame)
subFrame:SetSize(300, height);
subFrame:SetHighlightTexture(136477)
subFrame:SetPoint("TOPLEFT", last, point)
last = subFrame
if i == 1 then
point = "BOTTOMLEFT"
end
local texture = subFrame:CreateTexture("ARTWORK")
texture:SetAllPoints()
texture:SetColorTexture(1,0,0.1, 1)
local fontString = subFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fontString:SetPoint("CENTER")
fontString:SetText("hej")
end