Skip to content

Instantly share code, notes, and snippets.

@adelevie
Created July 29, 2012 19:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelevie/3201323 to your computer and use it in GitHub Desktop.
Save adelevie/3201323 to your computer and use it in GitHub Desktop.
width = 102 # width of rectangle
height = 40 # height of rectangle
pos_x = 3 # x coordinate for entire grid
pos_y = 3 # y coordinate for entire grid
y_margin = 3 # vertical space between rectangles
x_margin = 3 # horizontal space between rectangles
columns = 3 # number of columns
rows = 5 # number of rows
columns.times do |col| # number of columns
rows.times do |row| # number of rows
# frame = [[x,y], [width, height]]
# frame = [position of rectangle, size of rectangle]
frame = [[(col * width) + pos_x + (col * x_margin), (row * height) + pos_y + (row * y_margin)], [width, height]]
# adding the subview to the superview:
# v = UIView.alloc.initWithFrame(frame)
# view.addSubview(v)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment