CoreAnimationレイヤー内に文字列を表示したいのですが、残念ながらCATextLayerでは不十分です。これは主に、制約を使用するときに使用が難しく、テキストを折り返したいためです。
次のコード(PyObjC)を使用してNSLayoutManagerを使用しています。
NSGraphicsContext.saveGraphicsState()
# THIS SOLVES THIS ISSUE
CGContextSetShouldSmoothFonts(ctx, False)
graphics = NSGraphicsContext.graphicsContextWithGraphicsPort_flipped_(ctx, True)
NSGraphicsContext.setCurrentContext_(graphics)
height = size.height
xform = NSAffineTransform.transform();
xform.translateXBy_yBy_(0.0, height)
xform.scaleXBy_yBy_(1.0, -1.0)
xform.concat()
self.textContainer.setContainerSize_(size)
glyphRange = self.layoutManager.glyphRangeForTextContainer_(self.textContainer)
self.layoutManager.drawBackgroundForGlyphRange_atPoint_(glyphRange, topLeft)
self.layoutManager.drawGlyphsForGlyphRange_atPoint_(glyphRange, topLeft)
NSGraphicsContext.restoreGraphicsState()
これはすべて問題なく機能しますが、唯一の問題は、見栄えの悪いテキストを生成することです(ただし、アンチアライズされています)。
そして、これがNSLayoutManagerのバージョンです。
足りないものはありますか?