iPhone UILabel文字软阴影 [英] iPhone UILabel text soft shadow
问题描述
我知道iPhone上开箱即用的UILabel不支持柔和阴影。那么实现我自己的最佳方式是什么?
I know soft shadows are not supported by the UILabel out of the box, on the iPhone. So what would be the best way to implement my own one?
编辑:
显然我会继承 UILabel
并绘制-drawRect:
我的问题是,如何将标签的内容作为图形并绘制他们,模糊他们等...
Obviously I will subclass the UILabel
and draw in the -drawRect:
My question is, how do I get the contents of the label as graphics and draw around them, blur them etc...
编辑2:
我退回了大约一年后的这个问题。与此同时,我已经构建了一个类,允许您轻松地向标签添加柔和阴影并调整其半径等,并在文本本身上绘制渐变。你可以在GitHub上找到它: https://github.com/doukasd/iOS-组件/树/主/视图
I returned to this question about a year later. In the meantime I've built a class that allows you to easily add soft shadow to a label and tweak it's radius etc and also to draw gradients on the text itself. You can find it on GitHub: https://github.com/doukasd/iOS-Components/tree/master/Views
推荐答案
这个答案 这个类似的问题提供了在UILabel后面绘制模糊阴影的代码。作者使用CGContextSetShadow()为绘制的文本生成阴影。
This answer to this similar question provides code for drawing a blurred shadow behind a UILabel. The author uses CGContextSetShadow() to generate the shadow for the drawn text.
这篇关于iPhone UILabel文字软阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!