简体   繁体   English

UILabel文本阴影不能是任何颜色而是灰色

[英]Can't get UILabel text shadow to be any color but gray

So I'm setting UILabel.shadowColor to a non-gray color, but the shadow always appears as opaque 50% gray (or so). 所以我将UILabel.shadowColor设置为非灰色,但阴影始终显示为不透明的50%灰色(或左右)。 For example, I tried setting the shadow to red and I still see gray. 例如,我尝试将阴影设置为红色,我仍然看到灰色。 Has anyone else seen this? 有没有人见过这个? (This is the UILabel inside a custom nav bar back button) (这是自定义导航栏后退按钮内的UILabel)

I ran into this same problem while trying to add a non-gray drop shadow to a UIButton 's titleLabel . 在尝试向UIButtontitleLabel添加非灰色阴影时遇到了同样的问题。 The solution appears to be to set the properties of the button's layer instead: 解决方案似乎是设置按钮layer的属性:

button.titleLabel.layer.shadowColor = [UIColor whiteColor].CGColor;
button.titleLabel.layer.shadowOffset = CGSizeMake(0, 1);
button.titleLabel.layer.shadowOpacity = 1;
button.titleLabel.layer.shadowRadius = 0;

shadowOpacity is necessary for the effect to appear at all, and shadowRadius has to be set explicitly since the default is 3.0 (very blurry). shadowOpacity是效果完全显示所必需的,并且必须显式设置shadowRadius ,因为默认值为3.0(非常模糊)。

This solution requires #import <QuartzCore/QuartzCore.h> . 此解决方案需要#import <QuartzCore/QuartzCore.h>

你确定你没有将backgroundColor与shadowColor混淆吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM