九宫格
创建九宫格:
for (int i = 0; i < 4; i++) { int a = 50 + i % 3 * 60 + i % 3 * 20; int b = 50 + i / 3 * 60 + i / 3 * 20; UIButton * bun = [UIButton buttonWithType:UIButtonTypeCustom]; bun.frame = CGRectMake(a, b, 60, 60); bun.backgroundColor = [UIColor redColor]; [self.view addSubview:bun]; }
添加一个取余和取整的方法:
swift版本:
for i in 0...3 { print("取余是:\(i%3)") } for i in 0...3 { print("取整是:\(i/3)") }
控制台打印如下:
本文来自博客园,作者:稻草人11223,转载请注明原文链接:https://www.cnblogs.com/hero11223/p/5195932.html