CGContextShowTextAtPoint和空格 [英] CGContextShowTextAtPoint and white space

查看:82
本文介绍了CGContextShowTextAtPoint和空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么下面的代码忽略空白?

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);

在将字体名称更改为 Helvetica Neue时会产生空白:

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

有人知道这里发生了什么吗?

Does anyone understand whats going on here?

推荐答案

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.

这篇关于CGContextShowTextAtPoint和空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆