Question

I am following Brad's answer to apply glow effect in my CALayer text.

Here is my code:

- (void)drawLayer:(CALayer *)theLayer inContext:(CGContextRef)context
{   
    UIGraphicsPushContext(context);
    UIFont *font = [UIFont fontWithName:@"Verdana" size:11.0f];

    CGRect rect = CGRectMake(theLayer.bounds.origin.x + 5, theLayer.bounds.origin.y + 5, theLayer.bounds.size.width - 10, theLayer.bounds.size.height - 10);

    NSString * textToWrite = @"Some text";         

    UIColor *color = [ UIColor colorWithRed: (100.0f)  green: (50.0)  blue:(200.0f) alpha: 1.0f ];

    CGContextSetFillColorWithColor(context, color.CGColor); //this has no effect!!!

    CGContextSetShadowWithColor(context, CGSizeMake(0.0, 0.0), 2.0f, [UIColor greenColor].CGColor);

    [textToWrite drawInRect:rect withFont:font
          lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];       
 
    UIGraphicsPopContext();

}

I am getting a decent green glow here. However I want the text to have its own color too, apart from glow. For this I am using color variable here, along with CGContextSetFillColorWithColor. But it seems to have NO effect. The text seems white, with green glow. I want text with main color = color and glow=green.

What should I do?

Was it helpful?

Solution

I'm confused by your color... I think when declaring red green and blue in objective-c you set values that are up to 1.0 being the maximum (like you did with alpha) so when you give them their true 255 hex value you then divide by 255. Your color should be white since all 3 values are so far above the maximum... Maybe I'm wrong though first try these two codes...

Replace your current FillColorWithColor code with this:

[[UIColor colorWithCGColor:color] set];

(or maybe this...)

[[UIColor colorWithCGColor:color.CGColor] set];

If they don't work then try them while also changing your color code to this:

UIColor *color = [ UIColor colorWithRed: (100.0f/255.0f) green: (50.0f/255.0f) blue:(200.0f/255.0f) alpha: 1.0f ];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top