Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGContextShowTextAtPoint and white space

Why is it that the following code ignores the white-space? enter image description here

UIColor *textColor = [UIColor colorWithRed:153.0/255.0 green:102.0/255.0 blue:51.0/255.0 alpha:1.0];
CGContextSetFillColorWithColor(ctx, [textColor CGColor]);
CGContextSelectFont(ctx, "Helvetica Neue Bold" , 14, kCGEncodingMacRoman);
CGContextSetTextMatrix(ctx, CGAffineTransformMakeScale(1, -1)); 
CGContextSetShadowWithColor(ctx, CGSizeMake(0.0, 1.0), 1.0, [[UIColor whiteColor] CGColor]);
//CGContextSetAllowsAntialiasing(ctx, YES);

NSString *str = @"test1   test2";
CGContextShowTextAtPoint(ctx, 5, 17, [str UTF8String], str.length);

Where as changing the font name to "Helvetica Neue" produces the white space:

Does anyone understand whats going on here?

like image 605
vance Avatar asked Oct 11 '22 11:10

vance


1 Answers

CGContextShowTextAtPoint() is not the right way to show text using CoreGraphics, as misleading as that function name may be. Try CoreText instead.

like image 87
Ben Stiglitz Avatar answered Oct 30 '22 04:10

Ben Stiglitz