1

次の問題があります (以下のサンプル コード):定型化されたテキストの表示を
使用CATextLayerしています。NSAttributedString属性にストロークを追加するまで、すべて正常に機能します。ストロークを追加すると、テキストが非表示になり、ディスプレイにストロークだけが表示されます。何が起こるのか理解できません。テキストとストロークの両方を使用できないのはなぜですか? ありがとう。

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];
4

2 に答える 2

14

strokeWidth は、テキストとストロークの場合は負、ストロークのみの場合は正でなければなりません。Apple ドキュメントから:

kCTStrokeWidthAttributeName . この属性は、フォント ポイント サイズのパーセンテージとして解釈され、テキストの描画モードを制御します。正の値はストロークのみの描画に影響します。負の値はストロークと塗りつぶしです。

于 2013-01-31T11:32:36.430 に答える
0

kCGTextFillStroke を使用 - 塗りつぶしとストロークを同時に行う

于 2013-01-19T12:48:51.237 に答える