I have an array of words thats being collected and distributed with chosenWords array and would like to have the words in this array in red font when they are being distributed back in label text. I have tried NSattributed strings but with no luck.
here is my code
class GameVC: UIViewController {
@IBOutlet weak var storyLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if let Path = Bundle.main.url(forResource: "fortelling2", withExtension: "rtf") {
do {
let attributedStringWithRtf: NSAttributedString = try NSAttributedString(url: Path, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil)
self.storyLabel.attributedText = attributedStringWithRtf
self.storyLabel.font = UIFont(name: "TimesNewRomanPS-BoldItalicMT",
size: 30.0)
} catch let error {
print("Got an error \(error)")
}
while chosenWords.count > 1 {
let replace = storyLabel.text?.range(of: "§§§")
storyLabel.text?.replaceSubrange(replace!, with: chosenWords.removeFirst())
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
/
}
}