[英]NSMutableAttributedString - NSShadow without border
I tried out NSMutableAttributedString
to stylise my font with this code: 我尝试使用NSMutableAttributedString
来设置我的字体样式:
NSMutableAttributedString* attString = [[NSMutableAttributedString alloc] initWithString:element04.text];
NSRange range = NSMakeRange(0, [attString length]);
[attString addAttribute:NSFontAttributeName value:element04.font range:range];
[attString addAttribute:NSForegroundColorAttributeName value:element04.textColor range:range];
NSShadow* shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:30/255 green:11/255 blue:0/255 alpha:1];
shadow.shadowOffset = CGSizeMake(2.0f, 2.0f);
[attString addAttribute:NSShadowAttributeName value:shadow range:range];
[attString addAttribute:NSStrokeColorAttributeName value:[UIColor colorWithRed:30/255 green:11/255 blue:0/255 alpha:1] range:range];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-2.0] range:range];
element04.attributedText = attString;
The issue here is that there are border at the shadow. 这里的问题是阴影处有边界。 How can I add border to the text with the shadow that has no border? 如何使用没有边框的阴影为文本添加边框?
It is certainly not what I would have expected. 这肯定不是我所期望的。 I suggest that you should file a bug report with Apple - though I suspect you'll be told this behavior is intentional. 我建议您应该向Apple提交错误报告 - 尽管我怀疑您会被告知这种行为是故意的。 What's happening is that the stroke is casting a shadow of its own - and the weird part is that it is casting it on the fill , as if the layering order were: 发生的事情是,笔划正在投射出自己的阴影 - 奇怪的是它将它投射到填充上 ,就像分层顺序是:
You can make this much less annoying (and indeed rather pleasing) by adding a little shadowBlurRadius
. 你可以通过添加一点shadowBlurRadius
减少烦恼(实际上相当讨人喜欢)。 In the image below, I pretty much used your code, but added this: 在下图中,我几乎使用了您的代码,但添加了以下内容:
shadow.shadowBlurRadius = 3;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.