uibutton generated in a loop

Discussion in 'iOS Programming' started by sgs1, Mar 9, 2016.

  1. sgs1 macrumors newbie

    Joined:
    Jul 14, 2014
    #1
    Hello!

    I've a simple (but complicated for me) question to ask to you.
    I download an ID and subcategory name from a json that is generated from a php page on my hosting.
    Now, I would like to generate X uibutton of the same subcategory quantities that i've in my json.

    I've developed this code, but how I can insert a distance between the uibuttons that i've generated?

    Code:
    for(int i=0; i<[dataArray count];i++)
        {
         
            mydata= [dataArray objectAtIndex:i];
           
            NSString *sottocategoria =[mydata objectForKey:@"sottocategoria"];
            int idsottocategoria = [[mydata objectForKey:@"ID"] integerValue];
           
            float x = gap * (i+1) + width * i;
         
            UIButton *button_sottocategoria = [UIButton buttonWithType:UIButtonTypeSystem];
               button_sottocategoria.tag = idsottocategoria;
            [button_sottocategoria setTitle:sottocategoria forState:UIControlStateNormal];
                [button_sottocategoria setFrame:CGRectMake(x,y,width,height)];
            [self.view addSubview:button_sottocategoria];
    
       
        }
    
    Thanks for the help!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Looks like you already are trying to, via this line:
    Code:
    float x = gap * (i+1) + width * i;
    What is gap's value?
     

Share This Page