gpt4 book ai didi

objective-c - 如何给 NSText 多个阴影?

转载 作者:太空狗 更新时间:2023-10-30 03:37:47 25 4
gpt4 key购买 nike

我现在正在用

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

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

从 NSTextStorage 给文本一个阴影。但我想应用多个阴影,添加另一个 NSShadowAttributeName 只会覆盖之前的值。

如何添加多个阴影?可以用 CGContextSetShadowWithColor 来完成吗?

最佳答案

不确定请为您的 TextView 尝试下面的代码。当您在 textview 中写入字符串时,它将选择那么大的范围,并在此基础上绘制颜色:-

-(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];

}

}
}

关于objective-c - 如何给 NSText 多个阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19112809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com