UILabel 文本颜色透明度和图层阴影到位吗?
我有一个 UILabel,我试图将半透明渐变作为颜色应用到它上面。例如,在我的 UILabel
子类中,我尝试以这种方式设置渐变颜色:
self.textColor = [UIColor colorWithPatternImage:someTransparentGradient];
然而,在搞乱这个过程时,我发现 UILabel
似乎并不能够当图层阴影到位时以透明度进行绘制。我尝试将文本颜色设置为清除:
self.textColor = [UIColor clearColor];
但文本最终变成了白色。有想法吗?
如果将文本颜色设置为透明,然后将图层阴影应用到文本视图上,您可以自己复制该问题。
I have a UILabel
to which I am attempting to apply a semi-transparent gradient as a color onto. For example, in my UILabel
subclass I'm trying to set the gradient color this way:
self.textColor = [UIColor colorWithPatternImage:someTransparentGradient];
While messing around with this, however, I discovered that a UILabel
doesn't seem to be able to draw with transparency when layer shadows are in place. I attempted to set the text color to clear:
self.textColor = [UIColor clearColor];
but the text ended up being white. Ideas?
You can replicate the problem yourself if you set the text color to clear, then apply layer shadows onto the text view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您通过 nib 创建
UILabel
并在initWithFrame
中设置 textColor,您将不会获得所需的结果。在
UILabel
子类中,编写initWithCoder
并设置颜色。编辑
看,这是默认(灰色)背景的屏幕截图。
这是白色背景的屏幕截图
请下载示例应用程序并尝试一下。
If you would have created the
UILabel
through nib and set the textColor ininitWithFrame
, you will not get desired result.In the
UILabel
sub-class, writeinitWithCoder
and set the color.Edit
See, this is the screen shot with default (gray) background.
And this is the screenshot with white background
Please download the sample application and try it.
我通常不会接受自己的答案,但在这种情况下我必须接受。这似乎是一个错误。每当将图层阴影应用于
UILabel
时,就不再支持文本透明度。我将归档雷达。I don't normally accept my own answers, but in this case I must. This seems to be a bug. Whenever layer shadows are applied to a
UILabel
, text transparency is no longer supported. I will file a radar.