mruegenberg/objc-utils — Issue #4: Inner shadow for UILabel (with background color)
Author: urosmil
Created: 2011-12-30 15:47:49+00:00
State: open

Hi,

I'm trying to add inner shadow to UILabel with background color and my code looks like this:
- (void)drawRect:(CGRect)rect {
drawWithInnerShadow(rect, CGSizeMake(0,0), 5, [UIColor blackColor],
^ {
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
},
^ {
[[UIColor clearColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), rect);
});
[super drawRect:rect];
}

For some reason this doesn't draw shadow at all.

But when I change code in following way:
- (void)drawRect:(CGRect)rect {
drawWithInnerShadow(rect, CGSizeMake(0,0), 5, [UIColor blackColor],
^ {
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(1, 1, rect.size.width-2, rect.size.height-2));
},
^ {
[[UIColor clearColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(1, 1, rect.size.width-2, rect.size.height-2));
});
[super drawRect:rect];
}

Shadow is drown with offset of 1 pixel from every edge.

Is it possible to have shadow which will go to all edges? This is important since I have background color and 1 pixel offset is visible - especially on bright colors.

Regards,
Uros.