How to change UIButton font in Swift: 3 proven ways
Hi everyone! I'm a beginner in Swift and iOS development. I ran into a problem: I can't change the font for UIButton. I create a button through Interface Builder, connect an IBOutlet, and try to set the font programmatically.
Here's my code:
```swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Trying to change the font
myButton.titleLabel?.font = UIFont(name: "Helvetica-Bold", size: 20)
// Or like this:
myButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
}
}
```
But the font doesn't change! I've already tried different options: set the font in Interface Builder, changed it in code before and after setting the title. Sometimes
No answers yet.
Log in to leave an answer
Blogs
Docker and TypeScript: Application Containerization for Developers
Working with the File System in C#: A Complete Guide for Beginners
Task Queues in C#: A Complete Guide for Beginners
How to Open Access to localhost from Outside: TypeScript Solutions