From 8c5491d00bf7f958e8614b739c66bc1c231fc0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9D=E6=96=87=E5=8D=9A?= Date: Thu, 9 Jul 2015 22:53:13 +0800 Subject: [PATCH 1/4] UIColor Extension with hex color --- ExSwift/UIColor.swift | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ExSwift/UIColor.swift diff --git a/ExSwift/UIColor.swift b/ExSwift/UIColor.swift new file mode 100644 index 0000000..d4eefbe --- /dev/null +++ b/ExSwift/UIColor.swift @@ -0,0 +1,24 @@ +// +// UIColor.swift +// ExSwift +// +// Created by Kevin on 15/7/9. +// Copyright (c) 2015年 pNre. All rights reserved. +// + +import UIKit + +public extension UIColor { + + public convenience init?(hex: Int) { + self.init(hex: hex, alpha: 1.0) + } + + public convenience init?(hex: Int, alpha: CGFloat) { + let redPercent = (CGFloat)((hex & 0xff0000) >> 16) / 255.0 + let greenPercent = (CGFloat)((hex & 0xff00) >> 8) / 255.0 + let bluePercent = (CGFloat)(hex & 0xff) / 255.0 + + self.init(red: redPercent, green: greenPercent, blue: bluePercent, alpha: alpha) + } +} From 2dca37286f96a2ca8706897b7fce357d4f653d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9D=E6=96=87=E5=8D=9A?= Date: Thu, 9 Jul 2015 22:54:30 +0800 Subject: [PATCH 2/4] add UIColor Extension for hex pbxproj --- ExSwift.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ExSwift.xcodeproj/project.pbxproj b/ExSwift.xcodeproj/project.pbxproj index a27961b..5934fa1 100755 --- a/ExSwift.xcodeproj/project.pbxproj +++ b/ExSwift.xcodeproj/project.pbxproj @@ -87,6 +87,7 @@ CC633BA61A37142900341557 /* CharacterExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC633BA51A37142900341557 /* CharacterExtensionsTests.swift */; }; CC633BA71A37144E00341557 /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC8C1D701A365CA6003D386E /* Character.swift */; }; CC8C1D711A365CA6003D386E /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC8C1D701A365CA6003D386E /* Character.swift */; }; + DF00F2961B4EC1F900406084 /* UIColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF00F2951B4EC1F900406084 /* UIColor.swift */; }; F3AC8B534C220FCC23ECFD1A /* Pods_ExSwiftTests_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 886BBDB908D7803BE253AAA4 /* Pods_ExSwiftTests_iOS.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; /* End PBXBuildFile section */ @@ -158,6 +159,7 @@ CC8C1D701A365CA6003D386E /* Character.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Character.swift; sourceTree = ""; }; D287101692BE043B1DEF9DE1 /* Pods-ExSwiftTests-Mac.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExSwiftTests-Mac.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ExSwiftTests-Mac/Pods-ExSwiftTests-Mac.debug.xcconfig"; sourceTree = ""; }; DAAD7D28C374710DA8DAAA9B /* Pods-ExSwiftTests-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExSwiftTests-iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExSwiftTests-iOS/Pods-ExSwiftTests-iOS.release.xcconfig"; sourceTree = ""; }; + DF00F2951B4EC1F900406084 /* UIColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = ""; }; F24FF2CA18EA113B248D8C4D /* Pods-ExSwiftTests-Mac.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExSwiftTests-Mac.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExSwiftTests-Mac/Pods-ExSwiftTests-Mac.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -236,6 +238,7 @@ 12168FC91A22852300ED4105 /* NSDate.swift */, 6CB1F15E1A8AB867002EA767 /* Bool.swift */, 1E11AF891943222D006BCE48 /* ExSwift.h */, + DF00F2951B4EC1F900406084 /* UIColor.swift */, 1E11AF871943222D006BCE48 /* Supporting Files */, ); path = ExSwift; @@ -632,6 +635,7 @@ 24D9BC061AC54C1C000FDBB8 /* Float.swift in Sources */, 24D9BC071AC54C1C000FDBB8 /* Int.swift in Sources */, 24D9BC081AC54C1C000FDBB8 /* Range.swift in Sources */, + DF00F2961B4EC1F900406084 /* UIColor.swift in Sources */, 24D9BC091AC54C1C000FDBB8 /* String.swift in Sources */, 24D9BC0A1AC54C1C000FDBB8 /* NSArray.swift in Sources */, 24D9BC0B1AC54C1C000FDBB8 /* NSDate.swift in Sources */, From 7e9d11558f1e504a82ba71b01635b0d568c77cda Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 9 Jul 2015 23:07:05 +0800 Subject: [PATCH 3/4] document for UIColor Extension --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index c5d5604..a5824fe 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ components.takeFirst() { $0.completed } - [NSDate](#nsdate) - [Instance Methods](#instance-methods-9) - [Operators](#operators-4) + - [UIColor](#uicolor) + - [Init Methods](#init-methods-1) - [Utilities](#utilities) - [Class Methods](#class-methods-6) @@ -416,6 +418,14 @@ Name | Signatures **`>=`**|`>=(lhs: NSDate, rhs: NSDate) -> Bool` **`==`**|`==(lhs: NSDate, rhs: NSDate) -> Bool` +# UIColor # + +#### Init Methods #### +Name | Signatures +---- | ---- +**`hex`** |`(hex: Int)` +**`hex`** |`(hex: Int, alpha: CGFloat)` + # Utilities # Examples in the [Wiki](https://github.com/pNre/ExSwift/wiki/ExSwift) From ea6847da4c7f43988850a080887145bc05e219a3 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 9 Jul 2015 23:08:24 +0800 Subject: [PATCH 4/4] document for UIColor Extension --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5824fe..9422e45 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ components.takeFirst() { $0.completed } - [Instance Methods](#instance-methods-9) - [Operators](#operators-4) - [UIColor](#uicolor) - - [Init Methods](#init-methods-1) + - [Init Methods](#init-methods) - [Utilities](#utilities) - [Class Methods](#class-methods-6)