Awesome
UIColor+HexUtils
UIColor-HexUtils is a category for Hexadecimal Colors Support for UIColor. Support for prefixed # (#FFFFFF) or without (FFFFFF) Hexadecimal Colors.
RELEASE 2.0
Upgrade to Swift 5.
RELEASE 1.1
Updated Demo Project for CocoaPods and Fixes.
RELEASE 1.0
The base UIColor+Hex category with the required hex transformation functions.
Examples
Swift 5.0
// with hash
let colorHash = UIColor(hex: "#FFFFFF")
// without hash
let colorNoHash = UIColor(hex: "FFFFFF")
// short Hex
let colorShort = UIColor(hex: "FFF")
Demo Project
Check on Example Directory for the UIColor-HexUtilsExample project with Unit Tests.
Installation
CocoaPods
platform :ios
target 'YourTarget' do
pod 'UIColor-HexUtils', :git => "https://github.com/devcarlos/UIColor-HexUtils.git"
end
import UIColor+HexUtils
where you want to use UIColor+HexUtils extensions
Carthage
-
Get Carthage by running
brew install carthage
or choose another installation method -
Create a [Cartfile][] in the same directory where your
.xcodeproj
or.xcworkspace
is -
List the desired dependencies in the [Cartfile][], for example:
github "UIColor-HexUtils"
-
Run
carthage update
-
A
Cartfile.resolved
file and aCarthage
directory will appear in the same directory where your.xcodeproj
or.xcworkspace
is -
Drag the built
.framework
binaries fromCarthage/Build/<platform>
into your application’s Xcode project. -
If you are using Carthage for an application, follow the remaining steps, otherwise stop here.
-
On your application targets’ Build Phases settings tab, click the + icon and choose New Run Script Phase. Create a Run Script in which you specify your shell (ex:
/bin/sh
), add the following contents to the script area below the shell:/usr/local/bin/carthage copy-frameworks
-
Add the paths to the frameworks you want to use under “Input Files". For example:
$(SRCROOT)/Carthage/Build/iOS/UIColor_HexUtils.framework
-
Add the paths to the copied frameworks to the “Output Files”. For example:
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/UIColor_HexUtils.framework
Requirements
UIColor+HexUtils requires iOS 10.0 and above.
Credits
UIColors+HexUtils was created by Carlos Alcala because I was using in a lot of projects and wanted to contribute (and avoid the pain to always search for this functionality).
Creator
License
UIColors-HexUtils is available under the MIT license. See the LICENSE file for more info.