2013-07-22 78 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]; 
}