Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I give NSText multiple shadows?

Right now I'm using

NSShadow *textShadow = [NSShadow new];
textShadow.shadowBlurRadius = 5;
textShadow.shadowColor = [[NSColor whiteColor] colorWithAlphaComponent:.5];

[self addAttribute:NSShadowAttributeName value:textShadow range:NSMakeRange(0, self.length)];

from an NSTextStorage to give text a shadow. But I want to apply more than one shadow, and adding another NSShadowAttributeName just overwrites the previous value.

How can I add more than one shadow? Can it be done with CGContextSetShadowWithColor?

like image 267
zakdances Avatar asked Oct 01 '13 09:10

zakdances


1 Answers

Not sure please try this below code for your textview. When you write string inside textview it will select that much range and on the basis of that it draws the color:-

-(IBAction)createNewTabView:(id)sender
{
   NSString *allTheText =[tv string];
    NSArray *lines = [allTheText componentsSeparatedByString:@"\n"];
    NSString *str=[[NSString alloc]init];
    NSMutableAttributedString *attr;
    BOOL isNext=YES;
    [tv setString:@""];
    for (str in lines)
    {
        attr=[[NSMutableAttributedString alloc]initWithString:str];
        if ([str length] > 0)
        {

        NSRange range=NSMakeRange(0, [str length]);
        [attr addAttribute:NSBackgroundColorAttributeName value:[NSColor greenColor] range:range];
        [tv .textStorage appendAttributedString:attr];
            isNext=YES;
        }
        else
        {
            NSString *str=@"\n";
            NSAttributedString *attr=[[NSAttributedString alloc]initWithString:str];
            [tv .textStorage appendAttributedString:attr];
            isNext=NO;
        }
        if (isNext==YES)
        {
            NSString *str=@"\n";
            NSAttributedString *attr=[[NSAttributedString alloc]initWithString:str];
            [tv .textStorage appendAttributedString:attr];

        }

    }
    }
like image 179
Hussain Shabbir Avatar answered Sep 30 '22 07:09

Hussain Shabbir