0

私はNSMutablesstringに保存した文を持っています。タップすると文の単語をラベルにロードするボタンがあります。たとえば、「私は男の子です」を取り、ボタンをクリックすると「 i" をラベルに、"am" を別のラベルに、"a" を別のラベルに、"boy" を別のラベルに。

4

3 に答える 3

0
NSArray* labels = [@"i am a boy" componentsSeparatedByString: @" "];
CGFloat xOffset = 0.0;
for NSString *labeltext in labels
   UILabel *wordLabel = [[UILabel alloc] initWithFrame:CGRectMake(xOffset,0,300,40)];
   wordLabel.text  = word;
   xOffset+=200;
   [self.view addSubview:wordLabel];
于 2013-06-18T02:12:12.933 に答える
0

「私は男の子です」を配列に分割できます。

NSString* example = @"I am a boy";
NSArray *arr = [example componentsSeparatedByCharactersInSet:
          [NSCharacterSet characterSetWithCharactersInString:@" "]];

次に、 Text を UILabel に設定できます

http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/cl/NSString

于 2013-06-18T02:13:27.607 に答える
0
NSString *sentence = @"i am a boy";
NSMutableArray *words = [sentence componentsSeparatedByString:@" "];

CGFloat xVal = 0.0;

for( NSString *word in words ) {

    UILabel *wordLabel = [[UILabel alloc] initWithFrame:CGRectMake(xVal,0,200,40)];
    wordLabel.backgroundColor = [UIColor clearColor];
    wordLabel.textColor = [UIColor blackColor];
    wordLabel.text  = word;
    xVal+=200;

    [self.view addSubview:wordLabel];
}
于 2013-06-18T02:09:48.240 に答える