ios - 带有 CALayer 的 UILabel 阴影不绘制

标签 ios objective-c

我正在尝试使用标签的 CALayer 绘制 UILabel 的阴影。

好吧,这是我的代码:

    nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70.0, 2.0, 180.0, 40.0)];

    [nameLabel setFont:[UIFont fontWithName:@"HelveticaNeue-UltraLight" size:26.0]];
    [nameLabel setTextColor:[UIColor whiteColor]];
    [nameLabel setClipsToBounds:NO];
    [[nameLabel layer] setShadowColor:[UIColor blackColor].CGColor];
    [[nameLabel layer] setShadowOffset:CGSizeMake(1.0, 2.0)];
    [[nameLabel layer] setShadowRadius:20.0f];
    [[nameLabel layer] setShadowOpacity:0.5f];

标签包含在UIView中。 如果我只是将CALayer(并隐藏标签本身)作为子图层添加到 View 中,它只会显示文本,而不显示阴影。

设置setMasksToBoundssetShouldRasterize没有帮助。

有什么想法吗?

最佳答案

shadowRadius 的正值会使阴影模糊很多,小值或零值应该用于清晰可见的阴影。

关于ios - 带有 CALayer 的 UILabel 阴影不绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19958617/

相关文章:

iphone - 带有可重新排列按钮的 UIScrollView

ios - `-fembed-bitcode` 尝试存档应用程序时出错

ios - 如何用手指移动线条?

ios - 如何设置 Linux BlueZ 5 连接参数以实现 Apple iOS 兼容性

ios - 如何解决来自 Firebase 的 Apple Mach-O 链接器错误?

ios - 调整 UILabel 的字体,使文本适合标签的边界

ios - 如何从 UITableViewCell 转换到另一个 View Controller

objective-c - 在 Xcode 调试器中检查数组的内容

ios - 无法在某些 iPhone 模拟器中保存 UserDefault 数组 (swift 3)

ios - 警报延迟 - iOS swift