Reputation: 1242
I am a iphone game developer. Right now i am developing a book app for children. For that i need to change the color of the cclabel to change word by word with a voice dictating the text in the background. To make it work as a initial process
NSString *pstring1 = @"The moon is a big eye";
int ix = 600,iy = 300;
NSArray *str1 = [pstring1 componentsSeparatedByString:@" "];
NSLog(@"str1 %@",str1);
for(NSString* st in str1)
{
CCLOG(@"STRING IS %@ POSITION IS %d",st,ix);
CGFloat wid= 0;
CGFloat ss = [st sizeWithFont: [UIFont systemFontOfSize:25]].width;
wid = ss+(ss/10);
CCLabelTTF * labels = [CCLabelTTF labelWithString:st fontName:@"Marker Felt" fontSize:25 ];
[labels setPosition:CGPointMake(ix, iy)];
[labels setColor:ccBLUE];
ix+=wid+5;
[self addChild:labels];
For example i separated a string with white space and added it to an NSArray. And in the for loop i am getting the text width of the string in the array one by one using sizeWithFont and i have added it as CGFloat value.And i am creating cclabel for each word in the array and incrementing the width size according the word's width in the array which is saved in the CGFloat. The problem is there is more white space between each cclabel or it merges with one another.I don't know whether i am correct or wrong The output looks like this http://screencast.com/t/p8Rj8GKZ . Please help me to sort out this issue. If this is issue is sorted out means i will use timer and change the color of the each cclabel to show the word to word color change effect.
Upvotes: 1
Views: 442
Reputation: 1242
Finally i fixed the issue which i have mentioned above
I have just set the contentsize of the label to zero and now all the unwanted white space between the one word to the another got disappeared
[labels setContentSize:CGSizeZero];
Upvotes: 1