1

I need the label as enter image description here

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.

hgpl
  • 869
  • 4
  • 11
  • 20

2 Answers2

1

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];
}
Franck
  • 742
  • 3
  • 11
  • The proper effect is not coming.Please help. Struggling lot for this...:( – hgpl Feb 23 '12 at 07:30
  • Thanks Franck .But I think you didn't get my question.The question is to get the shade of the text not the shadow.If you look at the label then you will see there are two shades of blue in the text of this label.I have got the light shade ,now I want the dark shade. I you can help me in this matter then I will be really thankful to you.:) – hgpl Feb 24 '12 at 05:18
  • You probably mean this kind of gradient. The simplest way is to use self.textColor = [UIColor colorWithPatternImage:[UIImage imageName:"gradient.png"]]; Where gradient.png is an image you did and placed in your project. – Franck Feb 24 '12 at 14:07
0

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).

Peter Sarnowski
  • 11,900
  • 5
  • 36
  • 33
  • What do you mean 'didn't work'? The effect was not you wanted or you couldn't get it to work? – Peter Sarnowski Feb 23 '12 at 02:54
  • Samowski The effect didn't come as I want.It is effecting on the white color but I want the effect on the light blue color. – hgpl Feb 23 '12 at 05:51