Reputation: 869
I need the label as
I created one label subclass.Where I write the code as,
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
UIColor * textColor = [UIColor colorWithRed:57.0/255.0 green:100.0/255.0 blue:154.0/255.0 alpha:1.0];
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 3.5);
CGContextSetLineJoin(c, kCGLineJoinRound);
CGContextSetTextDrawingMode(c, kCGTextFillStroke);;
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
// self.shadowColor = [UIColor colorWithRed:11.0/255.0 green:63.0/255.0 blue:126.0/255.0 alpha:1.0];
//self.shadowOffset = CGSizeMake(0.5, -0.5);
[super drawTextInRect:rect];
}
By this I am getting the blue color text and white outline to that text.But I need to get the dark blue color shade. How can I do this? Please help me.
Upvotes: 1
Views: 592
Reputation: 742
You should probably have a look at the CGContextSetShadowWithColor method.
CGContextSetShadowWithColor (
context,
shadowSize,
shadowBlur,
color
);
I found an article that could help you on this website : http://majicjungle.com/blog/191/
EDIT
The following code works:
- (void)drawRect:(CGRect)rect
{
UIColor * textColor = [UIColor colorWithRed:57.0/255.0 green:100.0/255.0 blue:154.0/255.0 alpha:1.0];
CGContextRef c = UIGraphicsGetCurrentContext();
//save the context before add shadow otherwise the shadow will appear for both stroke and fill
CGContextSaveGState(c);
//this is where I add the shadow, and it works
CGContextSetShadowWithColor(c, CGSizeMake(2, 2), 3, [[UIColor grayColor] CGColor]);
CGContextSetLineWidth(c, 3.5);
CGContextSetLineJoin(c, kCGLineJoinRound);
CGContextSetTextDrawingMode(c, kCGTextStroke);;
self.textColor = [UIColor whiteColor];
[super drawTextInRect:rect];
//restore the context to clear the shadow
CGContextRestoreGState(c);
CGContextSetTextDrawingMode(c, kCGTextFill);
self.textColor = textColor;
[super drawTextInRect:rect];
}
Upvotes: 1
Reputation: 11970
Have you tried using the standard quartz properties like:
label.layer.shadowColor
label.layer.shadowOffset
(you need the QuartzCore framework in your project and to import the header).
Upvotes: 0