Skip to content

Commit 6317eca

Browse files
committed
added starting classes
1 parent 43807ad commit 6317eca

File tree

5 files changed

+254
-0
lines changed

5 files changed

+254
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// UIColorExtension.swift
3+
// application
4+
//
5+
// Created by Nicolas LELOUP on 13/07/2015.
6+
// Copyright © 2015 Nicolas LELOUP - Buzznative. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
public extension UIColor {
13+
/**
14+
Gives a random UIColor.
15+
16+
- Returns: UIColor
17+
*/
18+
public static func randomColor() -> UIColor {
19+
return UIColor(red: CGFloat(randomFloat(0, upper: 255.0)) / 255.0, green: CGFloat(randomFloat(0, upper: 255.0)) / 255.0, blue: CGFloat(randomFloat(0, upper: 255.0)) / 255.0, alpha: 1)
20+
}
21+
22+
/**
23+
Generates a random Float between a lower and an upper values.
24+
25+
- Parameters:
26+
- lower: the lower value
27+
- upper: the lower value
28+
29+
- Returns: UIColor
30+
*/
31+
private static func randomFloat(lower: Float = 0.0, upper: Float = 1.0) -> Float {
32+
let r = Float(arc4random()) / Float(UInt32.max)
33+
return (r * (upper - lower)) + lower
34+
}
35+
36+
/**
37+
Formats a hex color string to UIColor. If empty, Black. If invalid, White.
38+
39+
- Parameter hex: web format hex color without the #
40+
41+
- Returns: UIColor
42+
*/
43+
public static func colorFromHex(hex: String) -> UIColor {
44+
let scanner = NSScanner(string: hex)
45+
scanner.charactersToBeSkipped = NSCharacterSet.alphanumericCharacterSet().invertedSet
46+
47+
var value: UInt32 = 0;
48+
scanner.scanHexInt(&value)
49+
50+
let red = CGFloat(Float(Int(value >> 16) & 0x000000FF) / 255.0)
51+
let green = CGFloat(Float(Int(value >> 8) & 0x000000FF) / 255.0)
52+
let blue = CGFloat(Float(Int(value) & 0x000000FF) / 255.0)
53+
54+
return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
55+
}
56+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// UIFontExtension.swift
3+
//
4+
//
5+
// Created by Nicolas LELOUP on 19/08/2015.
6+
//
7+
//
8+
9+
import UIKit
10+
11+
public extension UIFont {
12+
/**
13+
Gives the UIFont for the given font name and font size
14+
15+
- Parameters:
16+
- customFontName: The name of your font
17+
- ofSize: The size of your font you want
18+
19+
- Return: UIFont
20+
*/
21+
public static func fontNamed(customFontName: String, ofSize fontSize: CGFloat) -> UIFont {
22+
return UIFont(name: customFontName, size: fontSize)!
23+
}
24+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXFileReference section */
10+
C88353E51CFD7A8E00C1E8E3 /* UIColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColorExtension.swift; sourceTree = "<group>"; };
11+
C88353E61CFD7A8E00C1E8E3 /* UIFontExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIFontExtension.swift; sourceTree = "<group>"; };
12+
C88353E71CFD7A8E00C1E8E3 /* UIViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewExtension.swift; sourceTree = "<group>"; };
13+
/* End PBXFileReference section */
14+
15+
/* Begin PBXGroup section */
16+
C88353DE1CFD79B500C1E8E3 = {
17+
isa = PBXGroup;
18+
children = (
19+
C88353E51CFD7A8E00C1E8E3 /* UIColorExtension.swift */,
20+
C88353E61CFD7A8E00C1E8E3 /* UIFontExtension.swift */,
21+
C88353E71CFD7A8E00C1E8E3 /* UIViewExtension.swift */,
22+
);
23+
sourceTree = "<group>";
24+
};
25+
/* End PBXGroup section */
26+
27+
/* Begin PBXProject section */
28+
C88353DF1CFD79B500C1E8E3 /* Project object */ = {
29+
isa = PBXProject;
30+
attributes = {
31+
LastUpgradeCheck = 0730;
32+
};
33+
buildConfigurationList = C88353E21CFD79B500C1E8E3 /* Build configuration list for PBXProject "UIKitExtensions" */;
34+
compatibilityVersion = "Xcode 3.2";
35+
developmentRegion = English;
36+
hasScannedForEncodings = 0;
37+
knownRegions = (
38+
en,
39+
);
40+
mainGroup = C88353DE1CFD79B500C1E8E3;
41+
projectDirPath = "";
42+
projectRoot = "";
43+
targets = (
44+
);
45+
};
46+
/* End PBXProject section */
47+
48+
/* Begin XCBuildConfiguration section */
49+
C88353E31CFD79B500C1E8E3 /* Debug */ = {
50+
isa = XCBuildConfiguration;
51+
buildSettings = {
52+
};
53+
name = Debug;
54+
};
55+
C88353E41CFD79B500C1E8E3 /* Release */ = {
56+
isa = XCBuildConfiguration;
57+
buildSettings = {
58+
};
59+
name = Release;
60+
};
61+
/* End XCBuildConfiguration section */
62+
63+
/* Begin XCConfigurationList section */
64+
C88353E21CFD79B500C1E8E3 /* Build configuration list for PBXProject "UIKitExtensions" */ = {
65+
isa = XCConfigurationList;
66+
buildConfigurations = (
67+
C88353E31CFD79B500C1E8E3 /* Debug */,
68+
C88353E41CFD79B500C1E8E3 /* Release */,
69+
);
70+
defaultConfigurationIsVisible = 0;
71+
defaultConfigurationName = Release;
72+
};
73+
/* End XCConfigurationList section */
74+
};
75+
rootObject = C88353DF1CFD79B500C1E8E3 /* Project object */;
76+
}

UIKitExtensions/UIKitExtensions.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// UIViewExtension.swift
3+
// application
4+
//
5+
// Created by Nicolas LELOUP on 02/09/2015.
6+
// Copyright (c) 2015 Nicolas LELOUP - Buzznative. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
typealias AnimationCompletionBlock = ((Bool) -> Void)
13+
14+
extension UIView {
15+
// MARK: Fading animations
16+
func fadeInNow() {
17+
self.fadeInNowWithCallback(nil)
18+
}
19+
20+
func fadeOutNow() {
21+
self.fadeOutNowWithCallback(nil)
22+
}
23+
24+
func fadeInNowWithCallback(completion: AnimationCompletionBlock?) {
25+
UIView.animateWithDuration(0.5, delay: 0, options: .CurveEaseOut, animations: {
26+
self.alpha = 1.0
27+
}, completion: completion)
28+
}
29+
30+
func fadeOutNowWithCallback(completion: AnimationCompletionBlock?) {
31+
UIView.animateWithDuration(0.5, delay: 0, options: .CurveEaseOut, animations: {
32+
self.alpha = 0.0
33+
}, completion: completion)
34+
}
35+
36+
func flash() {
37+
UIView.animateWithDuration(0.1, delay: 0, options: .CurveEaseOut, animations: { () -> Void in
38+
self.alpha = 1
39+
}) { (param) -> Void in
40+
UIView.animateWithDuration(0.1, delay: 0, options: .CurveEaseOut, animations: {
41+
self.alpha = 0
42+
}, completion: nil)
43+
}
44+
}
45+
46+
// MARK: Resizing animations
47+
func resizeWithFactor(factor: CGFloat) {
48+
self.resizeWithFactor(factor, completion: nil)
49+
}
50+
51+
func resizeWithFactor(factor: CGFloat, completion: AnimationCompletionBlock?) {
52+
let currentFrame = self.frame
53+
let width = currentFrame.size.width * factor
54+
let height = currentFrame.size.height * factor
55+
let leftOffset = (currentFrame.origin.x + (currentFrame.size.width * (1.0 - factor))) / 2
56+
let topOffset = (currentFrame.origin.y + (currentFrame.size.height * (1.0 - factor))) / 2
57+
let newFrame : CGRect = CGRectMake(leftOffset, topOffset, width, height)
58+
59+
UIView.animateWithDuration(0.4, delay: 0, options: .CurveEaseOut, animations: {
60+
self.frame = newFrame
61+
}, completion: completion)
62+
}
63+
64+
// MARK: Sliding animations
65+
func slideUp() {
66+
self.slideUp(nil)
67+
}
68+
69+
func slideUp(completion: ((Bool) -> Void)?) {
70+
let screenBound = UIScreen.mainScreen().bounds
71+
let currentFrame = self.frame
72+
let newFrame : CGRect = CGRectMake(currentFrame.origin.x, currentFrame.origin.y - screenBound.size.height, currentFrame.size.width, currentFrame.size.height)
73+
UIView.animateWithDuration(0.3, delay: 0, options: .CurveEaseOut, animations: {
74+
self.frame = newFrame
75+
}, completion: completion)
76+
}
77+
78+
func slideDown() {
79+
self.slideDown(nil)
80+
}
81+
82+
func slideDown(completion: ((Bool) -> Void)?) {
83+
let screenBound = UIScreen.mainScreen().bounds
84+
let currentFrame = self.frame
85+
let newFrame : CGRect = CGRectMake(currentFrame.origin.x, currentFrame.origin.y + screenBound.size.height, currentFrame.size.width, currentFrame.size.height)
86+
UIView.animateWithDuration(0.3, delay: 0, options: .CurveEaseOut, animations: {
87+
self.frame = newFrame
88+
}, completion: completion)
89+
}
90+
}
91+

0 commit comments

Comments
 (0)