CGContextShowTextAtPoint 和空白
为什么下面的代码会忽略空格?
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);
将字体名称更改为“Helvetica Neue”会产生空格:
有谁明白这里发生了什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CGContextShowTextAtPoint() 不是使用 CoreGraphics 显示文本的正确方法,正如该函数名称可能具有误导性一样。请尝试使用 CoreText 。
CGContextShowTextAtPoint()
is not the right way to show text using CoreGraphics, as misleading as that function name may be. Try CoreText instead.