'How to change UIButton titleLabel font on state change, eg. setTitleFont(_ font: UIFont, for state: UIControl.State) {}

I want to create a UIButton extension setTitleFont(_ font: UIFont, for state: UIControl.State) that can listen for a specific state and change the font when that state is set. I know of listening to a certain state's didSet and overriding that parameter, but I don't know how to listen for didSet and override inside a function. Here's some pseudocode for what I'm trying to do, in case I'm not being clear:

public func setTitleFont(_ font: UIFont, for state: UIControl.State) {
        switch state {
        case .highlighted:
            public override var isHighlighted: Bool {
                didSet {
                    self.titleLabel?.font = font
                }
            }
        case .normal:
            
        case .selected:
            
        case .application:
            
        case .disabled:
            
        case .focused:
            
        case .reserved:
        
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source