-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.swift
More file actions
130 lines (107 loc) · 3.72 KB
/
Utils.swift
File metadata and controls
130 lines (107 loc) · 3.72 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
//
// File.swift
// MickleDeals
//
// Created by Chan, Nicky on 8/3/15.
// Copyright © 2015 Chan, Nicky. All rights reserved.
//
import Foundation
import UIKit
extension Array {
mutating func removeObject<U: Equatable>(object: U) {
var index: Int?
for (idx, objectToCompare) in self.enumerate() {
if let to = objectToCompare as? U {
if object == to {
index = idx
}
}
}
if index != nil {
self.removeAtIndex(index!)
}
}
}
extension UIColor {
class func primaryColor() -> UIColor {
return UIColor(red:0.94, green:0.42, blue:0.0, alpha:1.0)
}
class func buttonColor() -> UIColor {
return UIColor(red:0.984, green:0.549, blue:0.0, alpha:1.0)
}
class func highlightCellColor() -> UIColor {
return UIColor(red:0.9, green:0.9, blue:0.9, alpha:1.0)
}
}
extension UIView {
func applyShadow(radius: CGFloat, opacity: Float, xOffset: CGFloat, yOffset: CGFloat, useShadowPath: Bool) {
self.layer.shadowRadius = radius
self.layer.shadowColor = UIColor.blackColor().CGColor
self.layer.shadowOpacity = opacity
self.layer.shadowOffset = CGSizeMake(xOffset, yOffset)
if useShadowPath {
self.layer.shadowPath = UIBezierPath(rect: self.bounds).CGPath
} else {
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.mainScreen().scale
}
}
func applyBarShadow() {
applyShadow(3, opacity: 0.6, xOffset: 0, yOffset: 1, useShadowPath: true)
}
func applyCellShadow() {
applyShadow(1, opacity: 0.2, xOffset: 1, yOffset: 1.5, useShadowPath: true)
self.backgroundColor = UIColor.whiteColor()
self.clipsToBounds = false
}
func applyButtonStyle() {
applyShadow(2, opacity: 0.4, xOffset: 1, yOffset: 1, useShadowPath: false)
self.layer.cornerRadius = 3
self.backgroundColor = UIColor.buttonColor()
}
func resizeToFitSubviews() {
var width: CGFloat = 0
var height: CGFloat = 0
for someView in self.subviews {
let aView = someView as! UIView
let newWidth = aView.frame.origin.x + aView.frame.width
let newHeight = aView.frame.origin.y + aView.frame.height
width = max(width, newWidth)
height = max(height, newHeight)
}
frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: width, height: height)
}
func resizeToFitHeight() {
var height: CGFloat = 0
for someView in self.subviews {
let aView = someView
height += aView.frame.height
NSLog("height = \(height)")
}
frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.width, height: height)
}
}
extension UIFont {
func bold() -> UIFont {
let descriptor = self.fontDescriptor().fontDescriptorWithSymbolicTraits(UIFontDescriptorSymbolicTraits.TraitBold)
return UIFont(descriptor: descriptor, size: 0)
}
}
extension UILabel {
func applyBoldAsBlack() {
if !MDConfig.isIos8Above {
self.font = UIFont(name: "Helvetica-Bold", size: self.font.pointSize)
}
}
}
class Utils {
static func adjustInsetWithArrow(view: UIButton) {
let arrowPadding: CGFloat = 16.0 //used to be 16 for old style
view.titleEdgeInsets = UIEdgeInsetsMake(0, -arrowPadding, 0, arrowPadding)
view.contentEdgeInsets = UIEdgeInsetsMake(0, arrowPadding, 0, 0)
view.sizeToFit()
}
static func isSmallDeviceWidth() -> Bool{
return MDConfig.deviceWidth <= 350
}
}