1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #define kButtonWidth 35 #define kButtonHeight 35 #define kButtonMargin 10 #define kTotalCol 7
//4.设置答案按钮 //清除按钮 for(UIView *view in self.optionsView.subviews) { [view removeFromSuperview]; } CGFloat answerW=self.answerView.bounds.size.width; NSUInteger length=question.answer.length; CGFloat answerX=(answerW-kButtonWidth*length-kButtonMargin*(length-1))*0.5; //创建所有答案的按钮 for (int i=0; i<length; i++) { CGFloat x=answerX+i*(kButtonMargin+kButtonWidth); UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(x, 0, kButtonWidth, kButtonHeight)]; [btn setBackgroundImage:[UIImage imageNamed:@"btn_answer"] forState:UIControlStateNormal]; [btn setBackgroundImage:[UIImage imageNamed:@"btn_answer_heighted"] forState:UIControlStateHighlighted]; [self.answerView addSubview:btn]; }
|