// // ViewController.swift // AttributedString // // Created by Peter Goldsmith on 27/02/2017. // import UIKit class ViewController: UIViewController { @IBOutlet var label: UILabel! override func viewDidLoad() { super.viewDidLoad() let attributedString = NSMutableAttributedString() // Strikethrough attribute let strikeThroughAttributes: [String: Any] = [ NSStrikethroughStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, NSForegroundColorAttributeName: UIColor.purple ] attributedString.append(NSAttributedString(string: "strikethrough", attributes: strikeThroughAttributes)) // If the below is appended, in iOS 10.3 (built against any SDK), it will // prevent the strikethrough appearing from the PRECEEDING string. let nonStrikeThroughAttributes: [String: Any] = [ NSStrikethroughStyleAttributeName: NSUnderlineStyle.styleNone.rawValue, NSForegroundColorAttributeName: UIColor.green ] attributedString.append(NSAttributedString(string: "no strikethrough", attributes: nonStrikeThroughAttributes)) // Build and run attached project with Xcode 8.2 with iOS 10.2 simulator. // You should see "strikethrough" in purple that has a strikethrough, and "not strikethrough" in green that has no strikethrough. // Using Xcode 8.3 against iOS 10.3 simulator, you should see the same, however you see "strikethrough" without any strikethrough. label.attributedText = attributedString } }