After clicking on the button, the fonts fly away while I drive a sample code

class UIPrimaryButtonV2: UIButton { private var title: String? = "" override init(frame: CGRect) { super.init(frame: frame) self.commonInit() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) self.commonInit() } func commonInit() { self.backgroundColor = UIColor.turquoise self.layer.borderColor = UIColor.turquoise.cgColor self.layer.cornerRadius = 5.0 self.layer.borderWidth = 1 self.titleLabel?.font = UIFont(name: "Quicksand-Bold", size: 13) self.titleLabel?.shadowColor = UIColor.clear self.setTitle(self.titleLabel?.text?.uppercased(), for: .normal) self.title = self.title(for: .normal) self.setAttributedTitle(self.getFormatText(string: self.title!, color: UIColor.white), for: .normal) self.setAttributedTitle(self.getFormatText(string: self.title!, color: UIColor.white), for: .highlighted) self.setAttributedTitle(self.getFormatText(string: self.title!, color: UIColor.white), for: .selected) self.setAttributedTitle(self.getFormatText(string: self.title!, color: UIColor.warmGrey), for: .disabled) } override var isEnabled: Bool { didSet { if !isEnabled { self.backgroundColor = UIColor.whiteTwo self.layer.borderColor = UIColor.white.cgColor } else { self.backgroundColor = UIColor.turquoise self.layer.borderColor = UIColor.turquoise.cgColor } } } override open var isHighlighted: Bool { didSet { if isHighlighted { self.backgroundColor = UIColor.aqua self.layer.borderColor = UIColor.aqua.cgColor } else { self.backgroundColor = UIColor.turquoise self.layer.borderColor = UIColor.turquoise.cgColor //self.setAttributedTitle(self.getFormatText(string: self.title!, color: UIColor.white), for: .highlighted) } } } private func getFormatText(string: String, color: UIColor) -> NSAttributedString { let attributedString = NSMutableAttributedString(string: string, attributes: [ .font: UIFont(name: "Quicksand-Bold", size: 13.0)!, .foregroundColor: color, .strokeColor: UIColor.clear, .strokeWidth: 0, kCTKernAttributeName as NSAttributedStringKey: 1.0 ]) return attributedString } 

} enter image description here

  • This opens via NavigationController - XandroGrAle

0