I want to display a string in a UILabel
, where part of it has a strikethrough style. It seems I can't put the strikethrough attribute on only part of the string. If it's on the whole string, it displays; but if it's on part of the string, it does not. Is this a bug? Am I missing something?
Here is some example code, and a screen shot.
class ViewController: UIViewController {
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let strikeAttrs = [NSStrikethroughStyleAttributeName:
NSUnderlineStyle.styleSingle.rawValue]
let str1 = NSMutableAttributedString()
str1.append(NSAttributedString(string: "aaa", attributes: strikeAttrs))
let str2 = NSMutableAttributedString()
str2.append(NSAttributedString(string: "aaa", attributes: nil))
str2.append(NSAttributedString(string: "bbb", attributes: strikeAttrs))
label1.attributedText = str1
label2.attributedText = str2
}
}
The screen looks like this: