Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Add UIColor Extension #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ExSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -158,6 +159,7 @@
CC8C1D701A365CA6003D386E /* Character.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Character.swift; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
DF00F2951B4EC1F900406084 /* UIColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIColor.swift; sourceTree = "<group>"; };
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 = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -236,6 +238,7 @@
12168FC91A22852300ED4105 /* NSDate.swift */,
6CB1F15E1A8AB867002EA767 /* Bool.swift */,
1E11AF891943222D006BCE48 /* ExSwift.h */,
DF00F2951B4EC1F900406084 /* UIColor.swift */,
1E11AF871943222D006BCE48 /* Supporting Files */,
);
path = ExSwift;
Expand Down Expand Up @@ -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 */,
Expand Down
24 changes: 24 additions & 0 deletions ExSwift/UIColor.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ components.takeFirst() { $0.completed }
- [NSDate](#nsdate)
- [Instance Methods](#instance-methods-9)
- [Operators](#operators-4)
- [UIColor](#uicolor)
- [Init Methods](#init-methods)

- [Utilities](#utilities)
- [Class Methods](#class-methods-6)
Expand Down Expand Up @@ -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)
Expand Down