I have button A with customized attributed text. Is there a way that I can change it foreground color with button B?
This is button A:
let buttonA: UIButton = {
let bt = UIButton(type: .system)
bt.titleLabel?.numberOfLines = 0
let attributedText = NSMutableAttributedString(string: "127", attributes: [NSAttributedStringKey.foregroundColor : UIColor.black])
bt.setAttributedTitle(attributedText, for: .normal)
return bt
}()
I would like to change only color and keep in mind string in NSMutableAttributedString is dynamic so I don't have the exact string to use to create another attributedText and do this from button B.
let attributedTextFromButtonB = NSMutableAttributedString(string: "127", attributes: [NSAttributedStringKey.foregroundColor : UIColor.white])
bt.setAttributedTitle(attributedText, for: .normal)
buttonA.setAttributedTitle(attributedTextFromButtonB, for: .normal)
Thanks!