【问题标题】:How can I set a shadow on a UILabel it's backgroundframe?如何在 UILabel 它的背景框上设置阴影?
【发布时间】:2012-05-31 11:33:05
【问题描述】:

我有一个 UILabel,这个标签有一个填充的背景色(它是我的 textView 的标题)。我想启用一个阴影,以便这个深色阴影落在 textview 上。

我已经在我的标签文本上实现了阴影。

        descriptionLabel.layer.shadowColor = [[UIColor blackColor] CGColor];
        descriptionLabel.layer.shadowOffset = CGSizeMake(4.0f, 0.0f);
        descriptionLabel.layer.shadowOpacity = 1.0f;
        descriptionLabel.layer.shadowRadius = 1.0f;

但是我希望在标签的完整框架下方有阴影(而不是文本)。

【问题讨论】:

    标签: iphone background uilabel layer shadow


    【解决方案1】:

    您可以将阴影路径更改为显式矩形,而不是使用图层内容:

    CGPathRef shadowPath = CGPathCreateWithRect(descriptionLabel.bounds, NULL);
    descriptionLabel.layer.shadowPath = shadowPath;
    CGPathRelease(shadowPath);
    

    这也是一种在向视图添加阴影时提高渲染性能的非常常用的技术。绘制一个固定的矩形阴影将比基于图层内容的阴影快很多倍。

    【讨论】:

      猜你喜欢
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多