有没有办法获取 UILabel 文本的 ShadowPath?
我目前正在使用 UILabel 来显示一些文本。我使用 CALayer 给它一个漂亮的阴影。但是:当我在屏幕上定位(和移动)大量 UILabel 元素时,性能非常糟糕。
我在一些博客文章中读到,设置 CALayer 的 ShadowPath 可以优化性能,我用圆角矩形进行了尝试,它确实有效。所以现在我试图弄清楚如何获取 UILabel 上文本的 ShadowPath。
有人有想法吗?否则我想我将不得不在 coregraphics 中渲染我的文本。
以下是矩形图层上的 ShadowPath 的示例:
backgroundImage.layer.shadowOffset = CGSizeMake(0, 0);
backgroundImage.layer.shadowRadius = LIST_TITLE_VIEW_SHADOW_SIZE;
backgroundImage.layer.shadowOpacity = LIST_TITLE_VIEW_SHADOW_OPACITY;
backgroundImage.layer.shadowPath = [UIBezierPath bezierPathWithRect:backgroundImage.bounds].CGPath;
I'm currently using a UILabel to display some text. I'm using CALayer to give it a nice shadow. But: performance is really bad when I'm positioning (and moving) a lot of UILabel elements on the screen.
I've read in a few blogposts that setting the shadowPath of a CALayer optimizes the performance, I gave it a shot with a rounded rectangle and it actually works. So now i'm trying to figure out how to get the shadowPath for a text on a UILabel.
Somebody that has an idea? Otherwise I'll have to render my text in coregraphics I guess.
Here's an example with the shadowPath on a rectangle layer:
backgroundImage.layer.shadowOffset = CGSizeMake(0, 0);
backgroundImage.layer.shadowRadius = LIST_TITLE_VIEW_SHADOW_SIZE;
backgroundImage.layer.shadowOpacity = LIST_TITLE_VIEW_SHADOW_OPACITY;
backgroundImage.layer.shadowPath = [UIBezierPath bezierPathWithRect:backgroundImage.bounds].CGPath;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个对我来说很有魅力的解决方案。只需从标签中制作一个图像,如本示例所示:
I´ve found a solution that works like a charm for me. Just make an Image from the label like in this sample: