<legend id='DRuAM'><style id='DRuAM'><dir id='DRuAM'><q id='DRuAM'></q></dir></style></legend>

    <small id='DRuAM'></small><noframes id='DRuAM'>

  1. <tfoot id='DRuAM'></tfoot>
        <bdo id='DRuAM'></bdo><ul id='DRuAM'></ul>
      <i id='DRuAM'><tr id='DRuAM'><dt id='DRuAM'><q id='DRuAM'><span id='DRuAM'><b id='DRuAM'><form id='DRuAM'><ins id='DRuAM'></ins><ul id='DRuAM'></ul><sub id='DRuAM'></sub></form><legend id='DRuAM'></legend><bdo id='DRuAM'><pre id='DRuAM'><center id='DRuAM'></center></pre></bdo></b><th id='DRuAM'></th></span></q></dt></tr></i><div id='DRuAM'><tfoot id='DRuAM'></tfoot><dl id='DRuAM'><fieldset id='DRuAM'></fieldset></dl></div>
    1. 如何随机放置 UIButton 和值

      时间:2023-07-07
      1. <small id='3Ikej'></small><noframes id='3Ikej'>

        <tfoot id='3Ikej'></tfoot>

          <legend id='3Ikej'><style id='3Ikej'><dir id='3Ikej'><q id='3Ikej'></q></dir></style></legend>

          <i id='3Ikej'><tr id='3Ikej'><dt id='3Ikej'><q id='3Ikej'><span id='3Ikej'><b id='3Ikej'><form id='3Ikej'><ins id='3Ikej'></ins><ul id='3Ikej'></ul><sub id='3Ikej'></sub></form><legend id='3Ikej'></legend><bdo id='3Ikej'><pre id='3Ikej'><center id='3Ikej'></center></pre></bdo></b><th id='3Ikej'></th></span></q></dt></tr></i><div id='3Ikej'><tfoot id='3Ikej'></tfoot><dl id='3Ikej'><fieldset id='3Ikej'></fieldset></dl></div>

              <tbody id='3Ikej'></tbody>

              • <bdo id='3Ikej'></bdo><ul id='3Ikej'></ul>
                本文介绍了如何随机放置 UIButton 和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个问题视图,将显示 4 个答案,只有 1 个是正确的.

                i have a question view and will show 4 answers, only 1 are correct.

                但我不希望同一个按钮始终是正确答案.

                but i do not want the same button to be always the correct answer.

                我想知道如何每次随机放置 4 个 UIButton 和值.

                i will like to know how do i do a random placement of 4 UIButton and value every time.

                当用户再次进入这个问题时,答案将在不同的按钮中

                when user go to this question again the answer will be in differ button

                我的 X,y,W,H 位置

                my placement of X,y,W,H

                按钮 15,219,230,45

                button 1 5,219,230,45

                按钮 25,273,230,45

                button 2 5,273,230,45

                按钮 3244,224,230,45

                button 3 244,224,230,45

                按钮 4244,273,230,45

                button 4 244,273,230,45

                推荐答案

                我碰巧在做一个类似的游戏应用程序,所以得到了一些肯定会有所帮助的代码.看看下面.请注意,我已经说明了您将调用正确的答案方法"和错误的答案方法"来表示正确和错误的按钮点击.

                I happened to be working on a similar game app, so got some code which will definitely help. Check it out below. Note that I've put it in that you'd call a 'correctAnswerMethod' and a 'wrongAnswerMethod' for the correct and incorrect button clicks.

                // Define the four buttons in their respective frames, create the first button as the correct one, we'll shuffle it later.
                UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                [button1 setTitle:@"Correct Answer" forState:UIControlStateNormal];
                [button1 addTarget:self action:@selector(correctAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
                [self.view addSubview:button1];
                
                UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                [button2 setTitle:@"Wrong Answer 1" forState:UIControlStateNormal];
                [button2 addTarget:self action:@selector(wrongAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
                [self.view addSubview:button2];
                
                UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                [button3 setTitle:@"Wrong Answer 2" forState:UIControlStateNormal];
                [button3 addTarget:self action:@selector(wrongAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
                [self.view addSubview:button3];
                
                UIButton *button4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                [button4 setTitle:@"Wrong Answer 3" forState:UIControlStateNormal];
                [button4 addTarget:self action:@selector(wrongAnswerMethod:) forControlEvents:UIControlEventTouchUpInside];
                [self.view addSubview:button4];
                
                
                //Create an array with the rectangles used for the frames
                NSMutableArray *indexArray = [NSMutableArray arrayWithObjects:
                                              [NSValue valueWithCGRect:CGRectMake(5, 219, 230, 45)], 
                                              [NSValue valueWithCGRect:CGRectMake(5, 273, 230, 45)], 
                                              [NSValue valueWithCGRect:CGRectMake(244, 219, 230, 45)], 
                                              [NSValue valueWithCGRect:CGRectMake(244, 273, 230, 45)], nil];
                
                //Randomize the array
                NSUInteger count = [indexArray count];
                for (NSUInteger i = 0; i < count; ++i) {
                    int nElements = count - i;
                    int n = (arc4random() % nElements) + i;
                    [indexArray exchangeObjectAtIndex:i withObjectAtIndex:n];
                }
                
                //Assign the frames
                button1.frame = [((NSValue *)[indexArray objectAtIndex:0]) CGRectValue];
                button2.frame = [((NSValue *)[indexArray objectAtIndex:1]) CGRectValue];
                button3.frame = [((NSValue *)[indexArray objectAtIndex:2]) CGRectValue];
                button4.frame = [((NSValue *)[indexArray objectAtIndex:3]) CGRectValue];
                

                这篇关于如何随机放置 UIButton 和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:UIButton 在所有设备上的形状都不正确 下一篇:第二次触摸动画

                相关文章

              • <i id='KcSBT'><tr id='KcSBT'><dt id='KcSBT'><q id='KcSBT'><span id='KcSBT'><b id='KcSBT'><form id='KcSBT'><ins id='KcSBT'></ins><ul id='KcSBT'></ul><sub id='KcSBT'></sub></form><legend id='KcSBT'></legend><bdo id='KcSBT'><pre id='KcSBT'><center id='KcSBT'></center></pre></bdo></b><th id='KcSBT'></th></span></q></dt></tr></i><div id='KcSBT'><tfoot id='KcSBT'></tfoot><dl id='KcSBT'><fieldset id='KcSBT'></fieldset></dl></div>

                  <bdo id='KcSBT'></bdo><ul id='KcSBT'></ul>
                <legend id='KcSBT'><style id='KcSBT'><dir id='KcSBT'><q id='KcSBT'></q></dir></style></legend>

                <small id='KcSBT'></small><noframes id='KcSBT'>

                    <tfoot id='KcSBT'></tfoot>