iOS アプリの場合、テキストの配列があり、UIScrollview 内で右側にテキストのリストを生成し、左側にボタンのリストを生成したいと考えています。ユーザーが右側から UIButton を押すと、左側のテキストがユーザーのデバイスのクリップボードにコピーされます...
for ループと NSArray を使用して、UILabels でテキストのリストを生成する方法を見つけました。ただし、プログラムでUIButtonを生成する方法はわかりません。また、各ボタンに配列からそれぞれの文字列をコピーさせる方法もわかりません(つまり、ボタン#3は配列から文字列#3(objectAtIndex#2)をコピーします)
これまでの私のコードは次のとおりです。
NSArray *copyText;
copyText = [NSArray arrayWithObjects: @"text to copy 1", "text to copy 2", "text to copy 3", "text to copy 4", nil];
int i = 0;
while (i < [copyText count]) {
UILabel *copyLabels = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, (ScrollView1.frame.size.width*2/3), 25)];
copyLabels.center = CGPointMake(ScrollView1.frame.size.width*2/3, ((i*25)+15));
copyLabels.textAlignment = UITextAlignmentCenter;
copyLabels.textColor = [UIColor blackColor];
copyLabels.backgroundColor = [UIColor clearColor];
copyLabels.font = [UIFont fontWithName:@"System" size:(16.0)];
[ScrollView1 addSubview:copyLabels];
copyLabels.text = [NSString stringWithString:[copyLabels objectAtIndex:i]];
i ++;
}