配列 count に基づいて、プログラムでいくつかのラベルを生成したいと考えています。
これに関する多くのリンクを見つけましたが、これに対する適切な回答を得ることができませんでした。生成しようとしています
for ループ内のこれらのラベル。私の要件のコーディング例を教えてもらえますか?
配列 count に基づいて、プログラムでいくつかのラベルを生成したいと考えています。
これに関する多くのリンクを見つけましたが、これに対する適切な回答を得ることができませんでした。生成しようとしています
for ループ内のこれらのラベル。私の要件のコーディング例を教えてもらえますか?
このようなもの?
float y = 40;
for (int i = 0; i < [myArray count]; i++) {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, y, 300, 30)];
[label setText:[myArray objectAtIndex:i]];
[self.view addSubview:label];
y += 40;
}
これは、y 原点が毎回 40 ずつインクリメントされるループでラベルを生成する方法の簡単なデモンストレーションです。
NSMutableArray *arr=[[NSMutableArray alloc]init];
//generate labels like this
for(int i=0;i<5;i++){
//set the frame or add to view or do anything with your label
UILabel *lbl=[[UILabel alloc] init];
[arr addObject:lbl];
}
//When you need to use , just iterate through the array and cast the objects back into UILabel
Uilabel *temp;
for(temp in arr){
UILabel *lbl=(UILabel*)temp;
}