如何将句子逐字分成框/框?

发布于 2024-12-20 02:00:05 字数 619 浏览 1 评论 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

I tried something like

//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:@", "];

But the result wasn't what I want. I want each frame will contain a word. eg [A] [book] [costs] ...etc

    // 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画尸师 2024-12-27 02:00:05

试试这个

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:@" "];

Try this

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:@" "];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文