-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOct1.swift
52 lines (41 loc) · 1.83 KB
/
Oct1.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import UIKit
import PlaygroundSupport
class ViewController: UIViewController, UIFontPickerViewControllerDelegate {
var label: UILabel!
var button: UIButton!
override func viewDidLoad() {
title = "Fun & Learn"
view.backgroundColor = .white
label = UILabel()
label.text = "Hello World"
label.font = UIFont.systemFont(ofSize: 24)
label.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(label)
button = UIButton(type: .system)
button.addTarget(self, action: #selector(presentFontPicker), for: .touchUpInside)
button.setTitle("Choose Font", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(button)
NSLayoutConstraint.activate([
label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
label.centerYAnchor.constraint(equalTo: view.centerYAnchor),
button.topAnchor.constraint(equalTo: label.bottomAnchor, constant: 20),
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.widthAnchor.constraint(equalToConstant: 100),
button.heightAnchor.constraint(equalToConstant: 44)
])
}
@objc func presentFontPicker() {
let picker = UIFontPickerViewController()
picker.delegate = self
present(picker, animated: true)
}
func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) {
guard let descriptor = viewController.selectedFontDescriptor else { return }
let font = UIFont(descriptor: descriptor, size: 24)
label.font = font
}
}
let master = ViewController()
let nav = UINavigationController(rootViewController: master)
PlaygroundPage.current.liveView = nav