-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQRCodeViewController.swift
More file actions
44 lines (35 loc) · 1.3 KB
/
QRCodeViewController.swift
File metadata and controls
44 lines (35 loc) · 1.3 KB
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
//
// QRCodeViewController.swift
// Example
//
// Created by Kirill Pustovalov on 04.06.2020.
// Copyright © 2020 Kirill Pustovalov. All rights reserved.
//
import UIKit
import TelegramColorPicker
class QRCodeViewController: UIViewController {
let builder = QRCodeBuilder()
@IBOutlet weak var qrCodeImageView: UIImageView!
@IBOutlet weak var qrCodeTextLabel: UILabel!
@IBOutlet weak var hexColorLabel: UILabel!
@IBOutlet weak var telegramColorPicker: TelegramColorPicker!
override func viewDidLoad() {
super.viewDidLoad()
qrCodeImageView.layer.magnificationFilter = .nearest
showQRCode(qrcode: builder.buildQRCode())
telegramColorPicker.getColorUpdate { [weak self] (_, color) in
guard let newColor = color.newValue, let hexadecimalColor = newColor.toHex() else { return }
self?.builder.foregroundColor = newColor
self?.hexColorLabel.textColor = newColor
self?.hexColorLabel.text = hexadecimalColor
}
}
func showQRCode(qrcode: QRCode) {
qrCodeImageView.image = qrcode.image
qrCodeTextLabel.text = qrcode.text
}
@IBAction func setColor(_ sender: Any) {
let qrCode = builder.buildQRCode()
showQRCode(qrcode: qrCode)
}
}