0 Replies
      Latest reply on Aug 2, 2018 9:12 PM by Luca_65
      Luca_65 Level 1 Level 1 (0 points)

        I wrote this code to add an image, a glyph, to a Button's title:

        let myAttribute: [NSAttributedString.Key : Any] = [ .foregroundColor : UIColor.yellow ]
        let myAttrString1 = NSMutableAttributedString(string: "", attributes: myAttribute)
        let image1Attachment = NSTextAttachment()
        image1Attachment.image = UIImage(named: "myImage")
        let image1String = NSAttributedString(attachment: image1Attachment)
        myAttrString1.append(image1String)
        myButton.setAttributedTitle(myAttrString1, for : UIControl.State.normal)
        let myAttrString2 = NSAttributedString(string: "selected", attributes: myAttribute)
        myButton.setAttributedTitle(myAttrString2, for: UIControl.State.selected)

        How can I change the glyph color?

        The color of the same glyph added as the Button Image follow setTitleColor but I'm not able to change the glyph color when in the attributed text.