1

I am trying to customise the display of a text view, by having specific lines in bold, and another color - but I can't seem to figure out how to add another color to the text as well. I have this function;

 func attributedText()->NSAttributedString{

        let string = "These Terms and Conditions are effective on July 24, 2016.\n\nBye " as NSString

        var attributedString = NSMutableAttributedString(string: string as String, attributes: [NSFontAttributeName:UIFont.systemFontOfSize(12.0)])

        let boldFontAttribute = [NSFontAttributeName: UIFont.boldSystemFontOfSize(12.0)]

        attributedString.addAttributes(boldFontAttribute, range: string.rangeOfString("These Terms and Conditions are effective on July 24, 2016."))
        attributedString.addAttributes(boldFontAttribute, range: string.rangeOfString("PLEASE NOTE:"))

        // 4
        return attributedString
    }

What more do I need to set a color for the text as well?

askaale
  • 1,199
  • 1
  • 23
  • 50
  • 1
    Side note: creating a String that you cast `as NSString` then using it with `as String` is nonsense. Just use a damn string from the start and don't cast. :) // And for your issue: this is the same idea you already know, declare a color attribute then add the attribute to a range in the attributedString. – Eric Aya Jul 26 '16 at 11:47
  • @EricD The thing is, I don't know. I found a snippet of this code on another thread here on StackOverflow. I don't have much experience dealing with attributes etc, and I have tried "var color = [NSStrokeColorAttributeName: UIColor.cyanColor()]" and set the attribute, with no luck. – askaale Jul 26 '16 at 11:55

0 Answers0