If we apply prominentGlass to button configuration, fonts shows default one.
button.configuration = .prominentGlass()
button.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .bold)
Instead of bold font with font size 18, it shows normal font with approx 14 font size.
Use setAttributedTitle
to set the title of the button, including any relevant formatting information. For example:
class ViewController: UIViewController {
private let button: UIButton = {
let button = UIButton(configuration: .prominentGlass())
button.translatesAutoresizingMaskIntoConstraints = false
if let attrFont = UIFont(name: "Helvetica", size: 40) {
let attrTitle = NSAttributedString(string: "Hello world", attributes: [NSAttributedString.Key.font: attrFont])
button.setAttributedTitle(attrTitle, for: UIControl.State.normal)
}
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(button)
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
@objc private func buttonTapped() {
print("Button tapped!")
}
}