iOS开发 创建九宫格按钮布局
2020-11-06 本文已影响0人
我是卖报的小行家
我的九宫格
CGFloat btnWidth = (self.view.frame.size.width - 80)/3;
for (int i = 0; i<9; i++) {
NSInteger colunm = i%3; //取余
NSInteger row = i/3;//整除
UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(20+colunm * (btnWidth+20), 200+row * (btnWidth+20), btnWidth, btnWidth)];
btn.tag = i;
btn.backgroundColor = [UIColor orangeColor];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(btnClicks:) forControlEvents:UIControlEventTouchUpInside];
}