首页 > 编程知识 正文

九宫格数独规律,九宫格遍历算法

时间:2023-05-04 06:20:57 阅读:276845 作者:2279

2019独角兽企业重金招聘Python工程师标准>>>

int totalColumns = 3; CGFloat top=100;

// 每一格的尺寸CGFloat cellW = 100;CGFloat cellH = 100;// 间隙CGFloat margin =(self.view.frame.size.width - totalColumns * cellW) / (totalColumns + 1);//根据格子个数创建对应的框框for(int index = 0; index< 9; index++) { UIView *cellView = [[UIView alloc ]init ]; cellView.backgroundColor = [UIColor blueColor]; // 计算行号 和 列号 int row = index / totalColumns; int col = index % totalColumns; //根据行号和列号来确定 子控件的坐标 CGFloat cellX = margin + col * (cellW + margin); CGFloat cellY = row * (cellH + margin); cellView.frame = CGRectMake(cellX, cellY+top, cellW, cellH); // 添加到view 中 [self.view addSubview:cellView]; }

转载于:https://my.oschina.net/u/2483781/blog/811034

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。