2011-12-07 32 views
0

我想是這樣如何將句子分隔成多個框/框 - 逐個詞?

//Putting the sentence into array 

NSString *list = (@"A book costs £50., Ken has saved £45., How much more does he need to save to buy the book?"); 
NSArray *listItems = [list componentsSeparatedByString:@", "]; 

但結果是不是我想要的。我希望每一幀都會包含一個單詞。例如,[A] [圖書] [費用] ...等

// to create a frame 

    CGRect frame= CGRectMake(50, 60, 50, 50); 
    comp *newBox = [[comp alloc] initWithFrame:frame ]; 
    [self.view addSubview:newBox]; 
    newBox.backgroundColor=[UIColor blueColor] 
    This frame work fine, i just need to put the word in to each frame 

回答

0

試試這個

NSString *list = (@"A book costs £50. Ken has saved £45. How much more does he need to save to buy the book?"); 
NSArray *listItems = [list componentsSeparatedByString:@" "]; 
+0

太棒了!爲什麼我從來沒有想過這個。還有一個問題想知道如何將每個單詞循環到不同的框架中?因爲我現在得到的是10個帶有全文的盒子。例如,[(A,書,成本,...)] [(A,書,成本,...)] [(A,書,成本,...)] – raymond

+0

沒關係,我到這兒來的問題:)謝謝 – raymond

相關問題