Inner Shadow in UILabel

后端 未结 6 1724
庸人自扰
庸人自扰 2020-12-04 05:10

is it possible to create such a UILabel with inner and outer shadow?

alt text http://dl.getdropbox.com/u/80699/Bildschirmfoto%202010-07-12%20um%2021.28.57.png

<
6条回答
  •  一个人的身影
    2020-12-04 05:47

    Yes, I have a blog post about it here. The short answer is to borrow the JTAInnerShadowLayer from here, subclass UILabel, and change its layerclass by overriding + (Class)layerClass so that it returns JTAInnerShadowLayer class like this:

    + (Class)layerClass
    {
      return [JTAInnerShadowLayer class];
    }
    

    Then in the init method for the layer set up the JTAInnerShadowLayer something like this:

    [self setBackgroundColor:[UIColor clearColor]];
    JTAInnerShadowLayer *innerShadow = (JTAInnerShadowLayer *)[self layer];
    [innerShadow setClipForAnyAlpha:YES];
    [innerShadow setOutsideShadowSize:CGSizeMake(0.0, 1.0) radius:1.0];
    [innerShadow setInsideShadowSize:CGSizeMake (0.0, 4.0) radius:6.0];
    /* Uncomment this to make the label also draw the text (won't work well
       with black text!*/
    //[innerShadow drawOriginalImage];
    

    (or just borrow the JTAIndentLabel class).

提交回复
热议问题