-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCreditsTVC.swift
148 lines (101 loc) · 4.72 KB
/
CreditsTVC.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
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
//
// CreditsTVC.swift
// ESEOmega
//
// Created by Tomn on 08/09/2017.
// Copyright © 2017 Thomas NAUDET. All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
import UIKit
fileprivate extension Selector {
/// Done button tapped
static let close = #selector(CreditsTVC.close)
}
class CreditsTVC: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Crédits"
tableView.emptyDataSetSource = self
tableView.emptyDataSetDelegate = self
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Fermer", style: .done,
target: self, action: .close)
/* ¯\_(ツ)_/¯ */
let imageView = UIImageView(image: #imageLiteral(resourceName: "ron"))
imageView.frame = CGRect(x: 0, y: -100,
width: view.bounds.width, height: 113)
imageView.autoresizingMask = .flexibleWidth
imageView.contentMode = .scaleAspectFit
tableView.addSubview(imageView)
}
// MARK: - Actions
func contact() {
Data.shared().mail(["ail.com", "n72@gm", "tom"].reversed().joined(), currentVC: self)
}
@objc func close() {
dismiss(animated: true)
}
}
extension CreditsTVC {
override func numberOfSections(in tableView: UITableView) -> Int {
return 0 // always show empty data set
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0 // always show empty data set
}
}
// MARK: Empty Data Set Source
extension CreditsTVC: DZNEmptyDataSetSource {
func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
return #imageLiteral(resourceName: "credits")
}
func title(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
return NSAttributedString(string: " ")
}
func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
let text = """
© Thomas NAUDET ESEOmega 2015-2018
© Benjamin GONDANGE Avéseo 2018-2019
© Romain RABOUAN ESEOKAMI 2019-2020
Une question, un problème ? ↓
"""
let subheadDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .subheadline)
let boldSubheadDescriptor = subheadDescriptor.withSymbolicTraits(.traitBold) ?? subheadDescriptor
let mas = NSMutableAttributedString(string: text,
attributes: [.font : UIFont.preferredFont(forTextStyle: .subheadline),
.foregroundColor : UIColor.lightGray])
let boldAttr = [NSAttributedStringKey.font : UIFont(descriptor: boldSubheadDescriptor, size: 0)]
mas.setAttributes(boldAttr, range: NSMakeRange(2, 13))
mas.setAttributes(boldAttr, range: NSMakeRange(36, 18))
mas.setAttributes(boldAttr, range: NSMakeRange(73, 15))
mas.setAttributes(boldAttr, range: NSMakeRange(text.count - 29, 29)) // question?
return mas
}
func buttonTitle(forEmptyDataSet scrollView: UIScrollView!, for state: UIControl.State) -> NSAttributedString! {
return NSAttributedString(string: "Contacter",
attributes: [.font : UIFont.preferredFont(forTextStyle: .headline),
.foregroundColor : UINavigationBar.appearance().barTintColor ?? .blue])
}
}
// MARK: Empty Data Set Delegate
extension CreditsTVC: DZNEmptyDataSetDelegate {
func emptyDataSetDidTapButton(_ scrollView: UIScrollView!) {
contact()
}
}
// MARK: Mail Compose View Controller Delegate
extension CreditsTVC: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult,
error: Error?) {
dismiss(animated: true)
}
}