我想动态创建标签,例如如果我有一个存储了25个字符的数组,我想动态地为这些字符创建25个标签。我很难管理X和Y坐标。如何管理X和Y坐标。 谁能帮我 。 任何帮助表示赞赏。
http://www.chicagonow.com/improv-class-for-the-soul/files/2012/01/Puzzled-1-Quandaries_Enigmas.jpg
答案 0 :(得分:1)
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];
}
}
使用此代码可以帮助您。在for循环中,你创建了Multiple Lable