- (void)viewDidLoad {
[super viewDidLoad];
int width=self.view.frame.size.width/6;
int height=(self.view.frame.size.height-100)/5;
for (int row=0;row<5;row++)
{
for (int column=0;column<6;column++)
{
MathProblem *problem=[[MathProblem alloc] initWithMax:10];
problem.view.frame=CGRectMake(column*width, height*row, width, height);
problem.controller=self;
// problem.view.frame=CGRectMake(40, 40, 100, 100);
[self.view addSubview:problem.view];
}
}
int buttonWidth=resultChoices.frame.size.width/10;
int buttonHeight=resultChoices.frame.size.height;
resultChoices.userInteractionEnabled=true;
self.view.userInteractionEnabled=true;
for (int i=0;i<10;i++)
{
UIButton *button=[[[UIButton alloc]init] retain];
button.tag=i;
button.frame=CGRectMake(i*buttonWidth,buttonHeight+resultChoices.frame.origin.y,buttonWidth,buttonHeight);
button.backgroundColor=[UIColor redColor];
button.userInteractionEnabled=true;
[button setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonChosen:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
}
- (IBAction) buttonChosen:(id)sender
{
UIButton *button=(UIButton*) sender;
int choice=button.tag;
if (currentProblem!=nil)
{
[currentProblem setChoice:choice];
}
}
No comments:
Post a Comment