mruegenberg/objc-utils

Inner shadow for UILabel (with background color)

Closed this issue · 2 comments

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.

Any news to this?

Closing since this issue is so old. If this is still a problem, please reopen in uikit-utils.