self.shopsView.clipsToBounds = YES;// 切图,只显示自身size大小上的子视图.
// 每一个商品的尺寸
CGFloat shopW = 80;
CGFloat shopH = 90;
// 一行的列数
int cols = 3;
// 每一列之间的间距
CGFloat colMargin = (self.shopsView.frame.size.width - cols * shopW) / (cols - 1);
// 每一行之间的间距
CGFloat rowMargin = 10;
// 创建一个父控件(整体:存放图片和文字)
UIView *shopView = [[UIView alloc] init];
shopView.backgroundColor = [UIColor redColor];
// 商品的索引
NSUInteger index = self.shopsView.subviews.count;
// 商品的x值
NSUInteger col = index % cols;
CGFloat shopX = col * (shopW + colMargin);
// 商品的y值
NSUInteger row = index / cols;
CGFloat shopY = row * (shopH + rowMargin);
shopView.frame = CGRectMake(shopX, shopY, shopW, shopH);
[self.shopsView addSubview:shopView];
// 获得index位置对应的商品数据
NSDictionary *shop = self.shops[index];
// 每一个商品的尺寸
CGFloat shopW = 80;
CGFloat shopH = 90;
// 一行的列数
int cols = 3;
// 每一列之间的间距
CGFloat colMargin = (self.shopsView.frame.size.width - cols * shopW) / (cols - 1);
// 每一行之间的间距
CGFloat rowMargin = 10;
// 创建一个父控件(整体:存放图片和文字)
UIView *shopView = [[UIView alloc] init];
shopView.backgroundColor = [UIColor redColor];
// 商品的索引
NSUInteger index = self.shopsView.subviews.count;
// 商品的x值
NSUInteger col = index % cols;
CGFloat shopX = col * (shopW + colMargin);
// 商品的y值
NSUInteger row = index / cols;
CGFloat shopY = row * (shopH + rowMargin);
shopView.frame = CGRectMake(shopX, shopY, shopW, shopH);
[self.shopsView addSubview:shopView];
// 获得index位置对应的商品数据
NSDictionary *shop = self.shops[index];