Adding strikethrough to NSAttributedString in iOS 11 with Swift
ios, nsattributedstring, strikethrough, swift
Solution
I use this to strike through a text in Xcode9/iOS11/Swift4 env
let strokeEffect: [NSAttributedStringKey : Any] = [
NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.strikethroughColor: UIColor.red,
]
let strokeString = NSAttributedString(string: "text", attributes: strokeEffect)
Problem
Having some issues getting strikethrough to work. Currently I'm doing the following: ``` theString.addAttributes([ NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue, NSAttributedStringKey.strikethroughColor: UIColor.white ], range: NSMakeRange(0, 1)) ``` It's not showing any sort of strikethrough though. Any ideas? I can't seem to find anything that works.