NSMutableAttributedString - NSShadow without border
I tried NSMutableAttributedString
styling my font with this code:
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 problem is there is a border in the shadow. How do I add a border to text with a shadow that has no border?
+3
source to share
1 answer
This is certainly not what I expected. I suggest that you post a bug report with Apple, although I suspect you will be told that this behavior is intentional. What happens is that the bump fades its own shadow - and the weird part is that it casts it over the fill as if the layer order were:
- Stroke
- Shadow
- Fill (foreground color)
You can make it much less annoying (and even quite enjoyable) by adding a little shadowBlurRadius
. In the image below, I pretty much used your code, but added:
shadow.shadowBlurRadius = 3;
0
source to share