-
Notifications
You must be signed in to change notification settings - Fork 5
/
CapturePreviewToolBar.swift
86 lines (69 loc) · 2.89 KB
/
CapturePreviewToolBar.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// CapturePreviewToolBar.swift
// WLPhotoPicker
//
// Created by Mr.Wang on 2022/1/17.
//
import UIKit
protocol CapturePreviewToolBarDelegate: AnyObject {
func toolBarDidClickCancelButton(_ toolBar: CapturePreviewToolBar)
func toolBarDidClickDoneButton(_ toolBar: CapturePreviewToolBar)
}
class CapturePreviewToolBar: UIView {
weak var delegate: CapturePreviewToolBarDelegate?
private let toolBarHeight: CGFloat = 54
private let toolBarContentView = UIStackView()
private let cancelButton = UIButton()
private let doneButton = UIButton()
private let gradientLayer = CAGradientLayer()
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .clear
layer.addSublayer(gradientLayer)
toolBarContentView.axis = .horizontal
toolBarContentView.distribution = .equalSpacing
toolBarContentView.alignment = .center
addSubview(toolBarContentView)
toolBarContentView.snp.makeConstraints { make in
make.left.equalTo(16)
make.right.equalTo(-16)
make.height.equalTo(toolBarHeight)
make.bottom.equalTo(-keyWindowSafeAreaInsets.bottom)
}
cancelButton.setTitle(BundleHelper.localizedString(.Cancel), for: .normal)
cancelButton.setTitleColor(.white, for: .normal)
cancelButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
cancelButton.addTarget(self, action: #selector(cancelButtonClick), for: .touchUpInside)
toolBarContentView.addArrangedSubview(cancelButton)
cancelButton.snp.makeConstraints { make in
make.width.equalTo(50)
}
doneButton.setTitle(BundleHelper.localizedString(.Confirm), for: .normal)
doneButton.setTitleColor(.white, for: .normal)
doneButton.titleLabel?.font = UIFont.systemFont(ofSize: 16)
doneButton.addTarget(self, action: #selector(doneButtonClick), for: .touchUpInside)
toolBarContentView.addArrangedSubview(doneButton)
doneButton.snp.makeConstraints { make in
make.width.equalTo(50)
}
}
override func layoutSubviews() {
super.layoutSubviews()
gradientLayer.frame = bounds
gradientLayer.colors = [UIColor(white: 0, alpha: 0).cgColor,
UIColor(white: 0, alpha: 0.4).cgColor]
gradientLayer.removeAllAnimations()
}
@objc private func cancelButtonClick() {
delegate?.toolBarDidClickCancelButton(self)
}
@objc private func doneButtonClick() {
delegate?.toolBarDidClickDoneButton(self)
}
override var intrinsicContentSize: CGSize {
return CGSize(width: UIScreen.width, height: toolBarHeight + keyWindowSafeAreaInsets.bottom)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}