diff --git a/.gitignore b/.gitignore index 8615121..f043339 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ DerivedData *.hmap *.ipa *.xcuserstate +*.xcworkspacedata # CocoaPods # diff --git a/Taylor.xcodeproj/project.pbxproj b/Taylor.xcodeproj/project.pbxproj index 404d6cb..fa9d035 100644 --- a/Taylor.xcodeproj/project.pbxproj +++ b/Taylor.xcodeproj/project.pbxproj @@ -7,10 +7,21 @@ objects = { /* Begin PBXBuildFile section */ - 7A3FC2B11CAC2ACC007A4063 /* UIEdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3FC2B01CAC2ACC007A4063 /* UIEdgeInsets.swift */; }; + 7A3FC2B11CAC2ACC007A4063 /* UIEdgeInsets+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3FC2B01CAC2ACC007A4063 /* UIEdgeInsets+Taylor.swift */; }; 7A3FC2B31CAC2B0B007A4063 /* UIEdgeInsetsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A3FC2B21CAC2B0B007A4063 /* UIEdgeInsetsTests.swift */; }; 7A44D05C1C187E030063575B /* Taylor.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A44D05B1C187E030063575B /* Taylor.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7A44D0631C187E030063575B /* Taylor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A44D0581C187E030063575B /* Taylor.framework */; }; + DFBC07AD1CAC399700A7A665 /* CGRect+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC079F1CAC399700A7A665 /* CGRect+Taylor.swift */; }; + DFBC07AE1CAC399700A7A665 /* CGSize+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A01CAC399700A7A665 /* CGSize+Taylor.swift */; }; + DFBC07B01CAC399700A7A665 /* Double+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A21CAC399700A7A665 /* Double+Taylor.swift */; }; + DFBC07B21CAC399700A7A665 /* NSDate+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A41CAC399700A7A665 /* NSDate+Taylor.swift */; }; + DFBC07B31CAC399700A7A665 /* Time.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A51CAC399700A7A665 /* Time.swift */; }; + DFBC07B41CAC399700A7A665 /* UIButton+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A61CAC399700A7A665 /* UIButton+Taylor.swift */; }; + DFBC07B51CAC399700A7A665 /* UIColor+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A71CAC399700A7A665 /* UIColor+Taylor.swift */; }; + DFBC07B61CAC399700A7A665 /* UIDevice+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A81CAC399700A7A665 /* UIDevice+Taylor.swift */; }; + DFBC07B71CAC399700A7A665 /* UIImageView+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07A91CAC399700A7A665 /* UIImageView+Taylor.swift */; }; + DFBC07B81CAC399700A7A665 /* UILabel+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07AA1CAC399700A7A665 /* UILabel+Taylor.swift */; }; + DFBC07B91CAC399700A7A665 /* UIScreen+Taylor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFBC07AB1CAC399700A7A665 /* UIScreen+Taylor.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -24,13 +35,24 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7A3FC2B01CAC2ACC007A4063 /* UIEdgeInsets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIEdgeInsets.swift; sourceTree = ""; }; + 7A3FC2B01CAC2ACC007A4063 /* UIEdgeInsets+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIEdgeInsets+Taylor.swift"; sourceTree = ""; }; 7A3FC2B21CAC2B0B007A4063 /* UIEdgeInsetsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIEdgeInsetsTests.swift; sourceTree = ""; }; 7A44D0581C187E030063575B /* Taylor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Taylor.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7A44D05B1C187E030063575B /* Taylor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Taylor.h; sourceTree = ""; }; 7A44D05D1C187E030063575B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7A44D0621C187E030063575B /* TaylorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TaylorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 7A44D0691C187E030063575B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DFBC079F1CAC399700A7A665 /* CGRect+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGRect+Taylor.swift"; sourceTree = ""; }; + DFBC07A01CAC399700A7A665 /* CGSize+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGSize+Taylor.swift"; sourceTree = ""; }; + DFBC07A21CAC399700A7A665 /* Double+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Double+Taylor.swift"; sourceTree = ""; }; + DFBC07A41CAC399700A7A665 /* NSDate+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSDate+Taylor.swift"; sourceTree = ""; }; + DFBC07A51CAC399700A7A665 /* Time.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Time.swift; sourceTree = ""; }; + DFBC07A61CAC399700A7A665 /* UIButton+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Taylor.swift"; sourceTree = ""; }; + DFBC07A71CAC399700A7A665 /* UIColor+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Taylor.swift"; sourceTree = ""; }; + DFBC07A81CAC399700A7A665 /* UIDevice+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIDevice+Taylor.swift"; sourceTree = ""; }; + DFBC07A91CAC399700A7A665 /* UIImageView+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+Taylor.swift"; sourceTree = ""; }; + DFBC07AA1CAC399700A7A665 /* UILabel+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILabel+Taylor.swift"; sourceTree = ""; }; + DFBC07AB1CAC399700A7A665 /* UIScreen+Taylor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIScreen+Taylor.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -73,9 +95,20 @@ 7A44D05A1C187E030063575B /* Taylor */ = { isa = PBXGroup; children = ( + DFBC079F1CAC399700A7A665 /* CGRect+Taylor.swift */, + DFBC07A01CAC399700A7A665 /* CGSize+Taylor.swift */, + DFBC07A21CAC399700A7A665 /* Double+Taylor.swift */, + DFBC07A41CAC399700A7A665 /* NSDate+Taylor.swift */, + DFBC07A51CAC399700A7A665 /* Time.swift */, + DFBC07A61CAC399700A7A665 /* UIButton+Taylor.swift */, + DFBC07A71CAC399700A7A665 /* UIColor+Taylor.swift */, + DFBC07A81CAC399700A7A665 /* UIDevice+Taylor.swift */, + 7A3FC2B01CAC2ACC007A4063 /* UIEdgeInsets+Taylor.swift */, + DFBC07A91CAC399700A7A665 /* UIImageView+Taylor.swift */, + DFBC07AA1CAC399700A7A665 /* UILabel+Taylor.swift */, + DFBC07AB1CAC399700A7A665 /* UIScreen+Taylor.swift */, 7A44D05B1C187E030063575B /* Taylor.h */, 7A44D05D1C187E030063575B /* Info.plist */, - 7A3FC2B01CAC2ACC007A4063 /* UIEdgeInsets.swift */, ); path = Taylor; sourceTree = ""; @@ -197,7 +230,18 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 7A3FC2B11CAC2ACC007A4063 /* UIEdgeInsets.swift in Sources */, + DFBC07B61CAC399700A7A665 /* UIDevice+Taylor.swift in Sources */, + 7A3FC2B11CAC2ACC007A4063 /* UIEdgeInsets+Taylor.swift in Sources */, + DFBC07AE1CAC399700A7A665 /* CGSize+Taylor.swift in Sources */, + DFBC07B21CAC399700A7A665 /* NSDate+Taylor.swift in Sources */, + DFBC07AD1CAC399700A7A665 /* CGRect+Taylor.swift in Sources */, + DFBC07B01CAC399700A7A665 /* Double+Taylor.swift in Sources */, + DFBC07B81CAC399700A7A665 /* UILabel+Taylor.swift in Sources */, + DFBC07B41CAC399700A7A665 /* UIButton+Taylor.swift in Sources */, + DFBC07B31CAC399700A7A665 /* Time.swift in Sources */, + DFBC07B71CAC399700A7A665 /* UIImageView+Taylor.swift in Sources */, + DFBC07B91CAC399700A7A665 /* UIScreen+Taylor.swift in Sources */, + DFBC07B51CAC399700A7A665 /* UIColor+Taylor.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Taylor/CGRect+Taylor.swift b/Taylor/CGRect+Taylor.swift new file mode 100644 index 0000000..fd29ffb --- /dev/null +++ b/Taylor/CGRect+Taylor.swift @@ -0,0 +1,72 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import Foundation + + +// swiftlint:disable variable_name + +extension CGRect +{ + var x: CGFloat { + set { + origin.x = newValue + } + + get { + return origin.x + } + } + + var y: CGFloat { + set { + origin.y = newValue + } + + get { + return origin.y + } + } + + var midX: CGFloat { + return x + width / 2 + } + + var midY: CGFloat { + return y + height / 2 + } + + var maxX: CGFloat { + return x + width + } + + var maxY: CGFloat { + return y + height + } +} + +// swiftlint:enable variable_name diff --git a/Taylor/CGSize+Taylor.swift b/Taylor/CGSize+Taylor.swift new file mode 100644 index 0000000..0355def --- /dev/null +++ b/Taylor/CGSize+Taylor.swift @@ -0,0 +1,47 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import Foundation + + +extension CGSize +{ + func inset(xOffset: CGFloat, yOffset: CGFloat) -> CGSize + { + return CGSize(width: self.width + xOffset, height: self.height + yOffset) + } + + func scale(xOffset: CGFloat, yOffset: CGFloat) -> CGSize + { + return CGSize(width: self.width * xOffset, height: self.height * yOffset) + } + + static func minimalTapableSize() -> CGSize + { + return CGSize(width: 44, height: 44) + } +} diff --git a/Taylor/Double+Taylor.swift b/Taylor/Double+Taylor.swift new file mode 100644 index 0000000..3ad665f --- /dev/null +++ b/Taylor/Double+Taylor.swift @@ -0,0 +1,40 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import Foundation + + +// swiftlint:disable variable_name + +extension Double +{ + var f: CGFloat { + return CGFloat(self) + } +} + +// swiftlint:enable variable_name diff --git a/Taylor/NSDate+Taylor.swift b/Taylor/NSDate+Taylor.swift new file mode 100644 index 0000000..48ad8b1 --- /dev/null +++ b/Taylor/NSDate+Taylor.swift @@ -0,0 +1,66 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import UIKit + + +extension NSDate +{ + func isSameDay(anotherDate: NSDate) + { + NSCalendar.currentCalendar().isDate(self, equalToDate: anotherDate, toUnitGranularity: .Day) + } + + + func daysBetween(toDate toDate: NSDate) -> Int + { + let components = NSCalendar.currentCalendar().components(.Day, fromDate: self, toDate: toDate, options: []) + return components.day + } + + func addDaysToDate(daysToAdd: Int) -> NSDate + { + return NSCalendar.currentCalendar().dateByAddingUnit(.Day, value: daysToAdd, toDate: self, options: [])! + } + + func getStartOfTheWeek() -> NSDate + { + let calendar = NSCalendar.currentCalendar() + var startOfTheWeek: NSDate? + var interval = NSTimeInterval(0) + + calendar.rangeOfUnit(.WeekOfMonth, startDate: &startOfTheWeek, interval: &interval, forDate: self) + + return startOfTheWeek! + } + + func getWeekDay() -> Int + { + let components = NSCalendar.currentCalendar().components(.Weekday, fromDate: self) + return components.weekday + } +} diff --git a/Taylor/Time.swift b/Taylor/Time.swift new file mode 100644 index 0000000..3fdcd97 --- /dev/null +++ b/Taylor/Time.swift @@ -0,0 +1,42 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import Foundation + + +/* + From http://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861 + Example use, switching light on after 2 seconds: + delay(2) { + println("📱👈 -> 💡") + light.switchOn() + } +*/ +func delay(delay: Double, closure:()->()) { + let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))) + dispatch_after(time, dispatch_get_main_queue(), closure) +} diff --git a/Taylor/UIButton+Taylor.swift b/Taylor/UIButton+Taylor.swift new file mode 100644 index 0000000..d72ee47 --- /dev/null +++ b/Taylor/UIButton+Taylor.swift @@ -0,0 +1,91 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import Foundation + + +extension UIButton +{ + /** + Set multiple UIButton's properties. All parameters are optionnals: + - text + - font + - text colors (Normal, Hightlighted, Selected, Disabled) + - text alignment + - backgroundColor + + and also optionnaly calls sizeToFit() to adjust the button's size. + */ + func setProperties(text text: String? = nil, font: UIFont? = nil, + normalTextColor: UIColor? = nil, highlightedTextColor: UIColor? = nil, selectedTextColor: UIColor? = nil, disabledTextColor: UIColor? = nil, + textAlignment: NSTextAlignment? = nil, backgroundColor: UIColor? = nil, fit: Bool = false) + { + if let font = font { + titleLabel?.setProperties(font: font, textAlignment: textAlignment) + } + + if let text = text { + setTitle(text, forState: .Normal) + } + + if let normalTextColor = normalTextColor { + setTitleColor(normalTextColor, forState: .Normal) + } + + if let highlightedTextColor = highlightedTextColor { + setTitleColor(highlightedTextColor, forState: .Highlighted) + } + + if let selectedTextColor = selectedTextColor { + setTitleColor(selectedTextColor, forState: .Selected) + } + + if let disabledTextColor = disabledTextColor { + setTitleColor(disabledTextColor, forState: .Disabled) + } + + if let backgroundColor = backgroundColor { + self.backgroundColor = backgroundColor + } + + if fit { + sizeToFit() + } + } + + /** + Set the UIButton image and call sizeToFit() to adjust the button size. + */ + func setImageAndFit(image: UIImage?, forState state: UIControlState, fit: Bool = false) + { + setImage(image, forState: state) + + if fit { + sizeToFit() + } + } +} diff --git a/Taylor/UIColor+Taylor.swift b/Taylor/UIColor+Taylor.swift new file mode 100644 index 0000000..e28f26d --- /dev/null +++ b/Taylor/UIColor+Taylor.swift @@ -0,0 +1,60 @@ +/// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import UIKit + + +extension UIColor +{ + class func colorBetweenColors(startColor startColor: UIColor, endColor: UIColor, percentage: CGFloat) -> UIColor + { + if percentage <= 0 { + return startColor + } else if percentage >= 1 { + return endColor + } + + var startRed: CGFloat = 0 + var startGreen: CGFloat = 0 + var startBlue: CGFloat = 0 + var startAlpha: CGFloat = 0 + startColor.getRed(&startRed, green: &startGreen, blue: &startBlue, alpha: &startAlpha) + + var endRed: CGFloat = 0 + var endGreen: CGFloat = 0 + var endBlue: CGFloat = 0 + var endAlpha: CGFloat = 0 + endColor.getRed(&endRed, green: &endGreen, blue: &endBlue, alpha: &endAlpha) + + let middleRed = Float(startRed + (percentage * (endRed - startRed))) + let middleGreen = Float(startGreen + (percentage * (endGreen - startGreen))) + let middleBlue = Float(startBlue + (percentage * (endBlue - startBlue))) + let middleAlpha = Float(startAlpha + (percentage * (endAlpha - startAlpha))) + + return UIColor(colorLiteralRed: middleRed, green: middleGreen, blue: middleBlue, alpha: middleAlpha) + } +} diff --git a/Taylor/UIDevice+Taylor.swift b/Taylor/UIDevice+Taylor.swift new file mode 100644 index 0000000..916e8d9 --- /dev/null +++ b/Taylor/UIDevice+Taylor.swift @@ -0,0 +1,48 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import Foundation + + +extension UIDevice +{ + // Returns true if the current device is an iPad (or an iPhone for isIPhone()) + class func isIPad() -> Bool + { + return UIDevice.currentDevice().userInterfaceIdiom == .Pad + } + + class func isIPadPro() -> Bool + { + return isIPad() && UIScreen.mainScreen().bounds.size.height == 1024 + } + + class func isIPhone() -> Bool + { + return UIDevice.currentDevice().userInterfaceIdiom == .Phone + } +} diff --git a/Taylor/UIEdgeInsets+Taylor.swift b/Taylor/UIEdgeInsets+Taylor.swift new file mode 100644 index 0000000..2554a22 --- /dev/null +++ b/Taylor/UIEdgeInsets+Taylor.swift @@ -0,0 +1,59 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import Foundation + + +public extension UIEdgeInsets +{ + static public var zero: UIEdgeInsets { return UIEdgeInsetsZero } + + static public func top(margin: CGFloat) -> UIEdgeInsets + { + return UIEdgeInsets(top: margin, left: 0, bottom: 0, right: 0) + } + + static public func left(margin: CGFloat) -> UIEdgeInsets + { + return UIEdgeInsets(top: 0, left: margin, bottom: 0, right: 0) + } + + static public func bottom(margin: CGFloat) -> UIEdgeInsets + { + return UIEdgeInsets(top: 0, left: 0, bottom: margin, right: 0) + } + + static public func right(margin: CGFloat) -> UIEdgeInsets + { + return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: margin) + } + + static func margins(margin: CGFloat) -> UIEdgeInsets + { + return UIEdgeInsets(top: margin, left: margin, bottom: margin, right: margin) + } +} diff --git a/Taylor/UIEdgeInsets.swift b/Taylor/UIEdgeInsets.swift deleted file mode 100644 index 7dd9780..0000000 --- a/Taylor/UIEdgeInsets.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// UIEdgeInsets.swift -// Taylor -// -// Created by Romain Pouclet on 2016-03-30. -// Copyright © 2016 Mirego. All rights reserved. -// - -import Foundation - -public extension UIEdgeInsets -{ - static public var zero: UIEdgeInsets { return UIEdgeInsetsZero } - - static public func top(margin: CGFloat) -> UIEdgeInsets - { - return UIEdgeInsets(top: margin, left: 0, bottom: 0, right: 0) - } - - static public func left(margin: CGFloat) -> UIEdgeInsets - { - return UIEdgeInsets(top: 0, left: margin, bottom: 0, right: 0) - } - - static public func bottom(margin: CGFloat) -> UIEdgeInsets - { - return UIEdgeInsets(top: 0, left: 0, bottom: margin, right: 0) - } - - static public func right(margin: CGFloat) -> UIEdgeInsets - { - return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: margin) - } - - static func margins(margin: CGFloat) -> UIEdgeInsets - { - return UIEdgeInsets(top: margin, left: margin, bottom: margin, right: margin) - } -} diff --git a/Taylor/UIImageView+Taylor.swift b/Taylor/UIImageView+Taylor.swift new file mode 100644 index 0000000..9c0339e --- /dev/null +++ b/Taylor/UIImageView+Taylor.swift @@ -0,0 +1,52 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import UIKit + + +extension UIImageView +{ + func setImageAndFit(image: UIImage?) + { + self.image = image + sizeToFit() + } + + // Returns the maximum size to perfectly fit the contained image using ScaleAspectFit content mode + func sizeThatFitsAspectFit(size: CGSize) -> CGSize + { + if let image = self.image { + if image.size.height / size.height > image.size.width / size.width { + return CGSize(width: size.height / image.size.height * image.size.width, height: size.height) + } else { + return CGSize(width: size.width, height: size.width / image.size.width * image.size.height) + } + } + + return CGSize.zero + } +} diff --git a/Taylor/UILabel+Taylor.swift b/Taylor/UILabel+Taylor.swift new file mode 100644 index 0000000..a9372c3 --- /dev/null +++ b/Taylor/UILabel+Taylor.swift @@ -0,0 +1,91 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import UIKit + + +extension UILabel +{ + /** + Set multiple UILabel's properties. All parameters are optionnals: + - text + - font + - text color + - text alignment + - line spacing + - multiline + + and also optionnaly calls sizeToFit() to adjust the label size. + */ + func setProperties(text text: String? = nil, font: UIFont? = nil, textColor: UIColor? = nil, highlightedTextColor: UIColor? = nil, lineSpacing: CGFloat? = nil, textAlignment: NSTextAlignment? = nil, fit: Bool = false, multiline: Bool? = nil) + { + if let text = text { + if let lineSpacing = lineSpacing { + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.lineSpacing = lineSpacing + paragraphStyle.lineBreakMode = .ByTruncatingTail + attributedText = NSAttributedString(string: text, attributes: [NSParagraphStyleAttributeName: paragraphStyle]) + } else { + self.text = text + } + } + + if let font = font { + self.font = font + } + + if let textColor = textColor { + self.textColor = textColor + } + + if let highlightedTextColor = highlightedTextColor { + self.highlightedTextColor = highlightedTextColor + } + + if let textAlignment = textAlignment { + self.textAlignment = textAlignment + } + + if let multiline = multiline { + numberOfLines = multiline ? 0 : 1 + lineBreakMode = multiline ? .ByWordWrapping : .ByTruncatingTail + } + + if fit { + sizeToFit() + } + } + + func setAttributedText(text: NSAttributedString?, fit: Bool = false) + { + attributedText = text + + if fit { + sizeToFit() + } + } +} diff --git a/Taylor/UIScreen+Taylor.swift b/Taylor/UIScreen+Taylor.swift new file mode 100644 index 0000000..b0d1486 --- /dev/null +++ b/Taylor/UIScreen+Taylor.swift @@ -0,0 +1,54 @@ +// Copyright (c) 2016, Mirego +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// - Neither the name of the Mirego nor the names of its contributors may +// be used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +import UIKit + + +extension UIScreen +{ + // Returns the point size of one pixel for the current screen + class var onePixel: CGFloat + { + return CGFloat(1.0) / self.mainScreen().scale + } + + // Returns a float value rounded to the nearest pixel for the current screen + class func roundFloatToPixel(value: CGFloat) -> CGFloat + { + return round(value * self.mainScreen().scale) / self.mainScreen().scale + } + + class func isBiggerThanIPhone5() -> Bool + { + return mainScreen().bounds.height > 568 + } + + class func isIPhone4() -> Bool + { + return mainScreen().bounds.height < 568 + } +}