2011-05-11 105 views
0

感謝您提供了一個很棒的網站,我是iOS編程的一員,並且非常有幫助。將UIButton隨機放置在視圖上

Actualy我有2個問題:

1)如何轉變的NSString字符的NSAray?
2)如何將UIButons 隨機放在視圖上,每個button.title顯示來自新char數組的一個char?我想做programaticaly

回答

0
  1. 要變換的NSString NSAray字符的:在視圖隨機

    NSMutableArray *characters = [[NSMutableArray alloc] 
    initWithCapacity:[myString length]]; 
    for (int i=0; i < [myString length]; i++) 
    { 
    NSString *ichar = [NSString stringWithFormat:@"%c", [myString characterAtIndex:i ]]; 
    
    [characters addObject:ichar]; 
    } 
    

2.place UIButons當每個button.title示出了來自新字符數組一個字符

UIButton *charButton = [[UIButton alloc]initWithFrame:CGRect(<Your required frame>)]; 
    charButton.titleLabel.text = [characters objectAtIndex:<ur required value>]; 
    [self.view addsubView:charbutton]