dreerr
dreerr

Reputation: 25

simple CATextLayer scaling problem

I'm having a simple scaling problem with CATextLayer, but i just couldn't figure it out: I want the CATextLayer to proportionally grow in size with it's superlayer: if the superlayer's width is 300 the text size of CATextLayer should be 12 and if the supeview's width is 600 the text size should be 24. I couldn't find a working solution!

Can you please give me a clue?

Thanks, Julian.

Upvotes: 0

Views: 1255

Answers (3)

shannoga
shannoga

Reputation: 19869

Had the same problem. You should -

 [textLayer setContentsScale:theScaleOfSuperLayer];

Upvotes: 0

Caroline
Caroline

Reputation: 4970

You can scale the font size proportionately. For example, if the superlayer's width changes from 300 to 600, that's 600/300 = 2. Then multiply the font size by 2.

Upvotes: 1

Rob Keniger
Rob Keniger

Reputation: 46020

If you want the layer to scale with its superlayer, you need to set its autoresizingMask property like so:

myTextLayer.autoresizingMask = ( kCALayerWidthSizable | kCALayerHeightSizable );

However, this probably won't change the size of the text as that's a fixed property of CATextLayer. You will probably have to change the size of the text in response to a change in the size of the layer yourself.

Upvotes: 0

Related Questions