开发者

Place UIButton randomly on the view

开发者 https://www.devze.com 2023-03-05 05:32 出处:网络
Thank you for a gr开发者_Go百科eat site, I am a biginner in iOS programming and find this site immensely helpfull.

Thank you for a gr开发者_Go百科eat site, I am a biginner in iOS programming and find this site immensely helpfull.

Actualy I have 2 questions:

1) How to transform NSString to NSAray of chars?

2) How to place UIButons randomly on the view when each button.title shows one char from new char array?

I would like to do it programaticaly.


  1. To transform NSString to NSAray of chars:

    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 randomly on the view when each button.title shows one char from new char array

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

精彩评论

暂无评论...
验证码 换一张
取 消