Strikethrough style is not rendered in iOS 14

I'm trying to use replaceCharacters(in:with:) of NSMutableAttributedString to replace a substring and apply different attributes. The problem is strikethroughStyle is not rendered for that substring.

Code Block swift
let s = NSMutableAttributedString(
    string: "hello world!",
    attributes: [.foregroundColor: UIColor.label]
)
let range = s.mutableString.range(of: "world")
s.replaceCharacters(
    in: range,
    with: NSAttributedString(
        string: "mars",
        attributes: [
            .strikethroughStyle: NSUnderlineStyle.single.rawValue,
            .strikethroughColor: UIColor.systemRed,
            .foregroundColor: UIColor.systemRed,
        ]
    )
)


Here, I can see that the color of the substring "mars" is changed, but there is no strikethrough line.

The same code is successfully working for iOS 13.

I've submitted FB8351249 related to this as well!
Seems that there is another report of this in FB8201732 too.
Is this a rendering problem or an attributed string problem? That is, if you enumerate each range of contiguous attributes using enumerateAttributes(in:options:using:), do you see the string through set?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
It seems like a rendering problem. I can see the strikethroughStyle, and strikethroughColor attributes attached to the substring "mars" when I enumerate.

It seems like a rendering problem.

OK. That puts it somewhat outside of my bailiwick, but I’ve added the UIKit tag to the thread and I hope that’ll attract the attention of someone more au fait with rendering.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
The issue seems to be happening when adding attributes to a part of the string. It seems to be working fine for striking through complete strings.
Also, enumerateAttributes(in:options:using:) has the strike through attributes. So looks like a rendering issue.
Apparently this issue gets fixed by setting the baselineOffset attribute to 1 (add the attribute to the list of attributes)
Just a test you could make.

Try replacing
Code Block
.strikethroughStyle: NSUnderlineStyle.single.rawValue,

with
Code Block
NSAttributedString.Key.strikethroughStyle: : NSUnderlineStyle.single.rawValue,

@perfectionaq's answer worked, but is not desirable for obvious reasons. I tried explicitly setting the baslineOffset to 0 and that worked perfectly without any side effects.
I had a similar strikethrough rendering issue and while it's not fixed in the latest, 14.0 GM, it is fixed in 12.2 Beta 1.
Actually it is even enough to add baselineOffset and set it to 0

Code Block
attributedString.addAttribute(NSAttributedString.Key.baselineOffset, value: 0, range: NSMakeRange(0,length))


Are we expecting Apple to fix this? I have this problem in 6 different applications and I can't go through all of them for a simple issue like this. Specially because this is only displayed on iOS 14.

Are we expecting Apple to fix this?

Have you tested your apps on the current 14.2 beta seed?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Experiencing the very same issue, compiled with Xcode 11.2.1, running on iOS 14 release version, the baselineOffset workaround doesn't appear to help.
We have managed to work around the issue using baselineOffset: 0.
Strikethrough style is not rendered in iOS 14
 
 
Q