添加笔触时文本不可见 [英] Text becomes invisible when stroke is added

查看:124
本文介绍了添加笔触时文本不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个问题(下面的示例代码):

我正在使用 CATextLayer NSAttributedString 以显示样式化的文本。一切正常,直到我将笔触添加到属性。当我添加笔画时-文本变得不可见,并且在显示中我只能看到笔画。
请问,我不知道会发生什么,为什么不能同时使用文字和笔画?
谢谢。

I have next issue (sample code below):
I'm use CATextLayer and NSAttributedString to displaying stylized text. All work fine until I had added stroke to attributes. When I add stroke - text becomes invisible and in display I can see only stroke. Please, I can't understand what happens, why I can't use both text and stroke? Thanks.

UIFont* font = [UIFont fontWithName: size:];
UIColor* strokeColor = [UIColor colorWithRed: green: blue: alpha:1.f];
UIColor* foregroundColor = [UIColor colorWithRed: green: blue: alpha:1.f];
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithNameAndSize(...);
CTFontRef ctFont = CTFontCreateWithFontDescriptor(...);

NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                            strokeWidth, kCTStrokeWidthAttributeName,
                            [strokeColor CGColor], kCTStrokeColorAttributeName,
                            ctFont, kCTFontAttributeName,
                            [foregroundColor CGColor], kCTForegroundColorAttributeName,
                            nil];

NSAttributedString* attributedText = 
[[NSAttributedString alloc] initWithString:text attributes:attributes];

CATextLayer* infoTextLayer = [[[CATextLayer alloc] init] autorelease];
infoTextLayer.string = attributedText;
...
infoTextLayer.frame = frame;
[self.layer addSublayer:infoTextLayer];


推荐答案

您的strokeWidth对于文本和笔触必须为负仅中风。从Apple Docs:

Your strokeWidth must be negative for text and stroke and positive for only stroke. From Apple Docs:


kCTStrokeWidthAttributeName 。此属性解释为字体点大小的百分比,它控制文本绘制模式:正值仅影响笔画。负值表示笔触和填充。

kCTStrokeWidthAttributeName. This attribute, interpreted as a percentage of font point size, controls the text drawing mode: positive values effect drawing with stroke only; negative values are for stroke and fill.

这篇关于添加笔触时文本不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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