-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabController.swift
More file actions
263 lines (225 loc) · 12.8 KB
/
TabController.swift
File metadata and controls
263 lines (225 loc) · 12.8 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//
// TabController.swift
// LiftApp
//
// Created by Austin Bailey on 8/4/17.
// Copyright © 2017 Austin Bailey. All rights reserved.
//
import UIKit
import CoreData
extension String {
var doubleValue: Double? {
return Double(self)
}
var floatValue: Float? {
return Float(self)
}
var integerValue: Int? {
return Int(self)
}
}
extension UIView {
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
}
@IBInspectable
var borderColor: UIColor? {
get {
let color = UIColor(cgColor: layer.borderColor!)
return color
}
set {
layer.borderColor = newValue?.cgColor
}
}
}
public extension UIView {
public enum ViewSide {
case top
case right
case bottom
case left
}
public func createBorder(side: ViewSide, thickness: CGFloat, color: UIColor, leftOffset: CGFloat = 0, rightOffset: CGFloat = 0, topOffset: CGFloat = 0, bottomOffset: CGFloat = 0) -> CALayer {
switch side {
case .top:
// Bottom Offset Has No Effect
// Subtract the bottomOffset from the height and the thickness to get our final y position.
// Add a left offset to our x to get our x position.
// Minus our rightOffset and negate the leftOffset from the width to get our endpoint for the border.
return _getOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: self.frame.size.width - leftOffset - rightOffset,
height: thickness), color: color)
case .right:
// Left Has No Effect
// Subtract bottomOffset from the height to get our end.
return _getOneSidedBorder(frame: CGRect(x: self.frame.size.width - thickness - rightOffset,
y: 0 + topOffset,
width: thickness,
height: self.frame.size.height), color: color)
case .bottom:
// Top has No Effect
// Subtract the bottomOffset from the height and the thickness to get our final y position.
// Add a left offset to our x to get our x position.
// Minus our rightOffset and negate the leftOffset from the width to get our endpoint for the border.
return _getOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: self.frame.size.height-thickness-bottomOffset,
width: self.frame.size.width - leftOffset - rightOffset,
height: thickness), color: color)
case .left:
// Right Has No Effect
return _getOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: thickness,
height: self.frame.size.height - topOffset - bottomOffset), color: color)
}
}
public func createViewBackedBorder(side: ViewSide, thickness: CGFloat, color: UIColor, leftOffset: CGFloat = 0, rightOffset: CGFloat = 0, topOffset: CGFloat = 0, bottomOffset: CGFloat = 0) -> UIView {
switch side {
case .top:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: self.frame.size.width - leftOffset - rightOffset,
height: thickness), color: color)
border.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin]
return border
case .right:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: self.frame.size.width-thickness-rightOffset,
y: 0 + topOffset, width: thickness,
height: self.frame.size.height - topOffset - bottomOffset), color: color)
border.autoresizingMask = [.flexibleHeight, .flexibleLeftMargin]
return border
case .bottom:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: self.frame.size.height-thickness-bottomOffset,
width: self.frame.size.width - leftOffset - rightOffset,
height: thickness), color: color)
border.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
return border
case .left:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: thickness,
height: self.frame.size.height - topOffset - bottomOffset), color: color)
border.autoresizingMask = [.flexibleHeight, .flexibleRightMargin]
return border
}
}
public func addBorder(side: ViewSide, thickness: CGFloat, color: UIColor, leftOffset: CGFloat = 0, rightOffset: CGFloat = 0, topOffset: CGFloat = 0, bottomOffset: CGFloat = 0) {
switch side {
case .top:
// Add leftOffset to our X to get start X position.
// Add topOffset to Y to get start Y position
// Subtract left offset from width to negate shifting from leftOffset.
// Subtract rightoffset from width to set end X and Width.
let border: CALayer = _getOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: self.frame.size.width - leftOffset - rightOffset,
height: thickness), color: color)
self.layer.addSublayer(border)
case .right:
// Subtract the rightOffset from our width + thickness to get our final x position.
// Add topOffset to our y to get our start y position.
// Subtract topOffset from our height, so our border doesn't extend past teh view.
// Subtract bottomOffset from the height to get our end.
let border: CALayer = _getOneSidedBorder(frame: CGRect(x: self.frame.size.width-thickness-rightOffset,
y: 0 + topOffset, width: thickness,
height: self.frame.size.height - topOffset - bottomOffset), color: color)
self.layer.addSublayer(border)
case .bottom:
// Subtract the bottomOffset from the height and the thickness to get our final y position.
// Add a left offset to our x to get our x position.
// Minus our rightOffset and negate the leftOffset from the width to get our endpoint for the border.
let border: CALayer = _getOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: self.frame.size.height-thickness-bottomOffset,
width: self.frame.size.width - leftOffset - rightOffset, height: thickness), color: color)
self.layer.addSublayer(border)
case .left:
let border: CALayer = _getOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: thickness,
height: self.frame.size.height - topOffset - bottomOffset), color: color)
self.layer.addSublayer(border)
}
}
public func addViewBackedBorder(side: ViewSide, thickness: CGFloat, color: UIColor, leftOffset: CGFloat = 0, rightOffset: CGFloat = 0, topOffset: CGFloat = 0, bottomOffset: CGFloat = 0) {
switch side {
case .top:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: self.frame.size.width - leftOffset - rightOffset,
height: thickness), color: color)
border.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin]
self.addSubview(border)
case .right:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: self.frame.size.width-thickness-rightOffset,
y: 0 + topOffset, width: thickness,
height: self.frame.size.height - topOffset - bottomOffset), color: color)
border.autoresizingMask = [.flexibleHeight, .flexibleLeftMargin]
self.addSubview(border)
case .bottom:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: self.frame.size.height-thickness-bottomOffset,
width: self.frame.size.width - leftOffset - rightOffset,
height: thickness), color: color)
border.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
self.addSubview(border)
case .left:
let border: UIView = _getViewBackedOneSidedBorder(frame: CGRect(x: 0 + leftOffset,
y: 0 + topOffset,
width: thickness,
height: self.frame.size.height - topOffset - bottomOffset), color: color)
border.autoresizingMask = [.flexibleHeight, .flexibleRightMargin]
self.addSubview(border)
}
}
//////////
// Private: Our methods call these to add their borders.
//////////
fileprivate func _getOneSidedBorder(frame: CGRect, color: UIColor) -> CALayer {
let border:CALayer = CALayer()
border.frame = frame
border.backgroundColor = color.cgColor
return border
}
fileprivate func _getViewBackedOneSidedBorder(frame: CGRect, color: UIColor) -> UIView {
let border:UIView = UIView.init(frame: frame)
border.backgroundColor = color
return border
}
}
extension UILabel {
}
class TabController: UITabBarController {
//hold these variables to pass data between view controllers
public static var currentUser: Int32?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//UILabel.appearance().font = UIFont(name: "System Light", size: 17)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.navigationItem.hidesBackButton = true
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}