2012-12-04 97 views
0

對於我的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 ++; 
    } 

回答