Search code examples
iosswiftuikituilabelstrikethrough

UILabel, TextField with overstrike character


I want to create a UILabel or UITextField with an overstruck character. (not a strikethru dash)For example:

enter image description here

is this possible in Swift 4/5 (Not SwiftUI). The hope is that this will roll into a text to show a correction and that the user adapting size will size as appropriate.

Note, I referenced several other questions and haven't found one that addresses character over character; only strikethru.


Solution

  • You can use NSAttributedString, and set the below attribute:

    let att = NSMutableAttributedString(string: "kfill")
    att.addAttribute(.kern, value: -7, range: NSRange(location: 0, length: 1))
    label.attributedText = att
    

    You can change the range and value if you wish to achieve different results.