- for (NSInteger i=0; i<self.dataArr.count; i++) {
- //行和列
- NSInteger row = i/colums;
- NSInteger col = i%colums;
- //计算x和y
- CGFloat circleX = SLMargin+((circleWH+hSpace)*col);
- CGFloat circleY = self.floorButton.bottom+16+ (circleWH+vSpace)*row;
- UIButton *circleButton = [UIButton buttonWithType:UIButtonTypeCustom];\
- [self.scrollView addSubview:circleButton];
- [circleButton setImage:[UIImage imageNamed:@"home_fire"] forState:UIControlStateNormal];
- circleButton.backgroundColor = [UIColor hex:@"#F9F9F9"];
- [circleButton setTitleColor:UIColor.greenColor forState:UIControlStateNormal];
- circleButton.frame = CGRectMake(circleX, circleY, circleWH, circleWH);
- circleButton.layer.cornerRadius = circleWH/2.0;
- [circleButton addTarget:self action:@selector(clickCircle:) forControlEvents:UIControlEventTouchUpInside];
- circleButton.backgroundColor = CustomBgColor;
- if (i==0) {
- //tmpBtn用于记录选中状态
- self.tmpBtn = circleButton;
- self.tmpBtn.backgroundColor = UIColor.orangeColor;
- }
- }
- //点击事件
- - (void)clickCircle:(UIButton *)sender
- {
- if (self.tmpBtn == sender) {
- sender.backgroundColor = UIColor.orangeColor;
- }else{
- sender.backgroundColor = UIColor.orangeColor;
- _tmpBtn.backgroundColor = CustomBgColor;
- }
- self.tmpBtn = sender;
- }