CGContextShowTextAtPoint and white space

徘徊边缘 提交于 2019-12-10 14:59:34

问题


Why is it that the following code ignores the white-space?

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?


回答1:


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



来源:https://stackoverflow.com/questions/5429004/cgcontextshowtextatpoint-and-white-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!