In 2021...
You just need to set the ButtonType to be .system and it will highlight when pressed.
let button = UIButton(type: .system)
Here's a button I made, for clarity:
lazy var myButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Show More", for: .normal)
button.setTitleColor(.systemBlue, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 17, weight: .regular)
button.layer.masksToBounds = true
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
return button
}()
@objc fileprivate func buttonTapped() {
//code for segue
}