循环,从一个数组
问题描述:
对于我的iOS应用生成与功能的按钮我有文字的数组,我想生成我的UIScrollView里面右手侧的文字和按钮的左侧列表的列表侧。 当用户按下从右侧从左边的文字将被复制到用户的设备的剪贴板一个UIButton ...循环,从一个数组
我想出如何使用for循环生成文本的UILabels列表和一个NSArray。我不知道如何以编程方式生成UIButtons不过,我也不知道如何使每个按钮从阵列复制相应的字符串(如按钮#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 ++;
}
答
的UIButton的具有在数值可以被分配,所以我的回路可以跟踪哪些按钮“标签”场哪一个。天才。