ankit yadav
ankit yadav

Reputation: 363

Want to create UI LABEL dynamically

I want to create labels dynamically For e.g. if i have an array with 25 characters stored in it ,i want to create 25 labels for those characters dynamically .I am confused in managing X and Y coordinates .how to manage X and Y coordinates for that. Can anyone help me . Any help appreciated .

http://www.chicagonow.com/improv-class-for-the-soul/files/2012/01/Puzzled-1-Quandaries_Enigmas.jpg

Upvotes: 0

Views: 118

Answers (1)

Virja Rahul
Virja Rahul

Reputation: 413

        int x;
    int y,h,w;
    x=15,y=0,h=135,w=135;
    //int i = array.count;
    int i = CategoryArray.count;
    for (j=0; j<i; j++) {
        if (j==0) {
            x=15;
            y=25;
        }
        else{   
            if (j%2==0) {
                x=15;
                y=y+20+135;
                mainScrollView.contentSize = CGSizeMake(242, 416+y-80);
            }
            else{
                x=x+135+20;
            }
        }


        
        UILabel *lblFirst = [[UILabel alloc]init] ;
        lblFirst.frame = CGRectMake(x, y, h, w);
        //lblFirst.font=[UIFont boldSystemFontOfSize:16];
        lblFirst.font=[UIFont systemFontOfSize:13];
        lblFirst.backgroundColor = [UIColor clearColor];
        lblFirst.textColor = [UIColor blackColor];
        [lblFirst setText:[[CategoryArray objectAtIndex:j]valueForKey:@"i_name"]];
        [btnImage addSubview:lblFirst];


    }
}

Use this code it will help you. in for loop you make Multiple Lable

Upvotes: 1

Related Questions