LoyaltyAnalysisViewController.swift
7.34 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//
// LoyaltyAnalysisViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
@objc public class LoyaltyAnalysisViewController: UIViewController {
@IBOutlet weak var leftButton: UIButton!
@IBOutlet weak var rightButton: UIButton!
@IBOutlet weak var leftLineView: UIView!
@IBOutlet weak var rightLineView: UIView!
@IBOutlet weak var contentView: UIView!
var pageController: UIPageViewController!
var tabSelected = 0
public override func viewDidLoad() {
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
// setup view
setBackButton()
setNavigationTitle("Ανάλυση")
// tab
leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
leftButton.setTitle("Εξαργυρωμένα", for:.normal)
leftButton.backgroundColor = . clear
leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
rightButton.setTitle("Μοιρασμένα δώρα", for:.normal)
rightButton.backgroundColor = . clear
rightButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
leftLineView.applyGradient(colours: [UIColor(rgb: 0x1DA6B9), UIColor(rgb: 0xB2CE69)], gradient: GradientOrientation.horizontal, cornerRadius: 0.0)
rightLineView.applyGradient(colours: [UIColor(rgb: 0x1DA6B9), UIColor(rgb: 0xB2CE69)], gradient: GradientOrientation.horizontal, cornerRadius: 0.0)
leftLineView.isHidden = false
rightLineView.isHidden = true
// pages
pageController = UIPageViewController(transitionStyle:.scroll, navigationOrientation:.horizontal)
pageController.dataSource = self;
pageController.delegate = self;
pageController.view.frame = contentView.bounds;
addChild(pageController)
contentView.addSubview(pageController.view)
pageController .didMove(toParent: self)
let analysisVC = self.viewControllerAt(0)
pageController.setViewControllers([analysisVC!], direction:.forward, animated:false)
}
////////////////////////////////////////////////////////////////////////////////
private func viewControllerAt(_ index:Int) -> AnalysisChildViewController?
{
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
if (index == 1) {
let analysisVC = storyboard.instantiateViewController(withIdentifier:"SharingHistoryViewController") as! SwiftWarplyFramework.SharingHistoryViewController
analysisVC.index = index;
return analysisVC;
}
let analysisVC = storyboard.instantiateViewController(withIdentifier:"HistoryViewController") as! SwiftWarplyFramework.HistoryViewController
analysisVC.index = index;
return analysisVC;
}
// MARK: - Handlers
@IBAction func handleLeft() {
if (tabSelected != 0) {
self.tabSelected = 0
UIView.animate(withDuration: 2.0, delay: 0.0) {
self.leftLineView.isHidden = false
self.rightLineView.isHidden = true
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.rightButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
}
let analysisVC = self.viewControllerAt(0)
pageController.setViewControllers([analysisVC!], direction:.reverse, animated:true)
}
}
@IBAction func handleRight() {
if (tabSelected != 1) {
self.tabSelected = 1
UIView.animate(withDuration: 2.0, delay: 0.0) {
self.leftLineView.isHidden = true
self.rightLineView.isHidden = false
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.leftButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
}
let analysisVC = self.viewControllerAt(1)
pageController.setViewControllers([analysisVC!], direction:.forward, animated:true)
}
}
}
// MARK: - PageViewController
extension LoyaltyAnalysisViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
if let analysisVC = viewController as? AnalysisChildViewController {
var index = analysisVC.index
if (index == 0) {
return nil;
}
index -= 1;
return viewControllerAt(index);
}
return nil;
}
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
if let analysisVC = viewController as? AnalysisChildViewController {
var index = analysisVC.index
if (index == 1) {
return nil;
}
index += 1;
return viewControllerAt(index);
}
return nil;
}
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if (!completed) {
return;
}
if let childVCs = pageViewController.viewControllers as? [AnalysisChildViewController] {
let currentIndex = childVCs[0].index
if (currentIndex == 0) {
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.rightButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
self.tabSelected = 0
self.leftLineView.isHidden = false
self.rightLineView.isHidden = true
} else {
self.leftButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Regular", size: 14)
self.rightButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Bold", size: 14)
self.rightButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
self.leftButton.setTitleColor(UIColor(rgb: 0x394A5B), for:.normal)
self.tabSelected = 1
self.leftLineView.isHidden = true
self.rightLineView.isHidden = false
}
}
}
}