-
Notifications
You must be signed in to change notification settings - Fork 74
/
FlashButton.swift
44 lines (39 loc) · 1.02 KB
/
FlashButton.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
//
// FlashButton.swift
// QRScannerSample
//
// Created by daichiro on 2019/11/08.
// Copyright © 2019 mercari.com. All rights reserved.
//
import UIKit
final class FlashButton: UIButton {
// MARK: - Initializer
override init(frame: CGRect) {
super.init(frame: frame)
settings()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
settings()
}
// MARK: - Properties
override var isSelected: Bool {
didSet {
let color: UIColor = isSelected ? .gray : .lightGray
backgroundColor = color.withAlphaComponent(0.7)
}
}
}
// MARK: - Private
private extension FlashButton {
func settings() {
setTitleColor(.darkGray, for: .normal)
setTitleColor(.white, for: .selected)
setTitle("OFF", for: .normal)
setTitle("ON", for: .selected)
tintColor = .clear
titleLabel?.font = .boldSystemFont(ofSize: 16)
layer.cornerRadius = frame.size.width / 2
isSelected = false
}
}