行號決定Y值
列號決定X值
// 一行的列數
int cols = 3;
// 每一個商品的尺寸
CGFloat shopW = 70;
CGFloat shopH = 90;
// 每一列之間的間距
int colMargin = (self.shopsView.frame.size.width - (cols*shopW))/(cols -1);
// 每一行之間的間距
int rowMargin = 10;
NSInteger index = self.shopsView.subviews.count;
// 列號
NSInteger col = index % cols ;
//行號
NSInteger row = index / cols;
CGFloat shopX = col *(colMargin + shopW); 列號決定X值
CGFloat shopY = row *(rowMargin + shopH); 行號決定Y值