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
?
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];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With