- NSString sizeWithFont, issue
- CGSize sz = [@"Test text to hilight without new line for testing" sizeWithFont:CGTextLabel.font];
- NSLog(NSStringFromCGSize(sz));
- str = @"Test text to hilight without new line for testing";
- self.words = [NSMutableArray arrayWithArray:[str componentsSeparatedByString:@" "]];
- CGFloat pos = 0;
- [self.rects addObject:[NSValue valueWithCGPoint:CGPointMake(0, 0)]];
- for(int i = 0; i < [self.words count]; i++)
- {
- NSString *w = [self.words objectAtIndex:i];
- NSLog(w);
- CGSize sz = [w sizeWithFont:CGTextLabel.font];
- pos += sz.width;
- pos += [@" " sizeWithFont:CGTextLabel.font].width;
- if(i != [self.words count]-1)
- {
- [self.rects addObject:[NSValue valueWithCGPoint:CGPointMake(pos, 0)]];
- }
- else {
- NSLog(@"%f",pos); //here actual calculated width is printed.
- }
- }
- CGSize size1 = [@"Hello There" sizeWithFont:[UIFont systemFontOfSize:12]];
- CGSize size2 = [@" " sizeWithFont:[UIFont systemFontOfSize:12]];
- CGSize size3 = [@"Hello" sizeWithFont:[UIFont systemFontOfSize:12]];
- CGSize size4 = [@"There" sizeWithFont:[UIFont systemFontOfSize:12]];
- CGSize size5 = [@"Hello There Hello There" sizeWithFont:[UIFont systemFontOfSize:12]];
- NSLog(NSStringFromCGSize(size1));
- NSLog(NSStringFromCGSize(size2));
- NSLog(NSStringFromCGSize(size3));
- NSLog(NSStringFromCGSize(size4));
- NSLog(NSStringFromCGSize(size5));
- 2012-07-17 10:57:40.513 TesterProject[62378:f803] {63, 15}
- 2012-07-17 10:57:40.514 TesterProject[62378:f803] {4, 15}
- 2012-07-17 10:57:40.514 TesterProject[62378:f803] {28, 15}
- 2012-07-17 10:57:40.514 TesterProject[62378:f803] {32, 15}
- 2012-07-17 10:57:40.514 TesterProject[62378:f803] {128, 15}
- CGSize size = [@"HelloThere" sizeWithFont:[UIFont systemFontOfSize:12]];