2013-07-22 186 views
3

我有一个CATextlayer的问题。我为CATextlayer设置了包装== YES,并自动为此设置多行。但行间距非常小,看起来很糟糕。 有没有办法为CATextlayer设置行间距?谢谢。CATextlayer设置行距?

回答

2

我觉得CATextLayer仅用于轻量级的使用。您可以将其string属性设置为NSAttributedString以更改字体和大小等属性,但会忽略其他属性,包括行高和间距。

为了更好地控制图层中文本的呈现方式,您可以使用常规的CALayerNSAttributedString的绘图方法;例如:

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { 
    [NSGraphicsContext saveGraphicsState]; 
    [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES]]; 
    [self.someAttributedString drawInRect:layer.bounds]; 
    [NSGraphicsContext restoreGraphicsState]; 
}