简单的CATextLayer缩放问题
我遇到了 CATextLayer 的简单缩放问题,但我就是无法弄清楚: 我希望 CATextLayer 的大小与其超级层成比例增长: 如果 superlayer 的宽度为 300,则 CATextLayer 的文本大小应为 12;如果 superview 的宽度为 600,则文本大小应为 24。 我找不到可行的解决方案!
你能给我一个线索吗?
谢谢,朱利安。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以按比例缩放字体大小。例如,如果超级图层的宽度从 300 更改为 600,则 600/300 = 2。然后将字体大小乘以 2。
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.
如果您希望图层与其超级图层一起缩放,则需要设置其
autoresizingMask
属性,如下所示:但是,这可能不会改变文本的大小,因为这是
的固定属性CATextLayer
。您可能必须自己更改文本的大小以响应图层大小的变化。If you want the layer to scale with its superlayer, you need to set its
autoresizingMask
property like so: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.有同样的问题。
你应该——
Had the same problem.
You should -