GSGrid
是一组基本的 struct,用于帮助构建基本的网格布局。
它允许您指定一个具有指定行数和列数、边界以及间距宽度和高度的 GSGrid
结构,然后在该网格内计算 CGRect
。
例如
GSGrid grid = GSGridMake(GSGridSizeMake(2, 2), CGRectMake(0.0, 0.0, 60.0, 60.0), CGSizeMake(2.0, 2.0));
CGRect rect = CGRectWithGridRectInGrid(GSGridRectMake(0, 0, 1, 1), grid);
NSLog(@"%@", NSStringFromCGRect(rect));
> {{0, 0}, {29, 29}}
此代码返回一个 2x2 的网格中第一个单元,面积为 60pt,垂直和水平间距为 2pt。
自动处理将矩形四舍五入到整数像素数的工作,以确保相邻矩形间出现恒定的间距。
GSGridPoint GSGridPointMake(NSInteger x, NSInteger y);
GSGridSize GSGridSizeMake(NSInteger columns, NSInteger rows);
GSGridRect GSGridRectMake(NSInteger x, NSInteger y, NSInteger columns, NSInteger rows);
GSGrid GSGridMake(GSGridSize size, CGRect bounds, CGSize gutter);
CGRect CGRectWithGridRectInGrid(GSGridRect rect, GSGrid grid);
CGRect CGRectWithIndexInGrid(NSUInteger index, GSGrid grid);