mruegenberg/objc-utils

How to use InnerShadowDrawing

Closed this issue · 6 comments

Hi M,

How can one use your InnerShadowDrawing? Can you supply a short readme or example?

Thanks,

Maarten

Sure. Here is some example code:

#import "InnerShadowDrawing.h"

// ....

- (void)drawRect:(CGRect)rect {
    drawWithInnerShadow(rect, CGSizeMake(3,3), 5, [UIColor blackColor], 
    ^ {
            ["Hello, World" drawInRect:self.bounds withFont:[UIFont boldSystemFontOfSize:24]];
    },
    ^ {
        [[UIColor redColor] set];
        ["Hello, World" drawInRect:self.bounds withFont:[UIFont boldSystemFontOfSize:24]];
    });
}

// ...

If you have any further questions, please ask.

Boom! Great. Thanks a lot!

Any idea what could be wrong with this code:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    drawWithInnerShadow(rect, CGSizeMake(2.0, 2.0), 2.0, [UIColor blackColor], ^{
        CGContextFillRect(context, self.bounds);
    }, ^{
        [[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0] setFill];
        CGContextFillRect(context, self.bounds);
    });
}

Only the red rectangle without the inner shadow is drawn. If I try the string drawing example from above, everything works as expected.

Looks like it should work to me... Maybe try UIRectFill instead of CGContextFillRect?

Hello, i don't understand how i can use it in my uilabel, i have initialized it in this way:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];

in my viewdidload method, now what i can do to use your class?

thanks for your work!

The class works only if you do your own drawing, it is not possible to use is directly with UILabel.

Instead, you'd have to write your own class and use InnerShadowDrawing in its drawRect: method.