A simple UIColor category to get color with hex code.

Related tags

Color TFTColor
Overview

TFTColor

A simple UIColor library to get UIColor object from RGB hex string/value, CMYK hex string/value or CMYK base component values. You can also retrieve back RGB hex string/value, CMYK hex string/value.

Awesome iOS Swift Version Objective C License DOI Build Status

Features

  • Convert RGB Hex String/Value to UIColor
  • Convert CMYK Hex String/Value to UIColor
  • Get RGB Hex String/Value from UIColor
  • Get CMYK Hex String/Value from UIColor
  • Initialize CMYK from its base components
  • The beautiful part of this library is that you can input Hex values with #, 0x or 0X and the it will take care of this.
  • Also you can input hex value of any length and this will be handled.
  • The library also takes care of non-hex characters.

Supporting Formats for RGB Hex Strings:

  1. #B
  2. #BB
  3. #RGB
  4. #GGBB
  5. #RGGBB
  6. #RRGGBB

Supporting Formats for CMYK Hex Strings:

  1. #K
  2. #KK
  3. #YKK
  4. #CMYK
  5. #MYYKK
  6. #MMYYKK
  7. #CMMYYKK
  8. #CCMMYYKK

Requirements

  • iOS 8.0+
  • Xcode 7.3+

Installation

CocoaPods

You can use CocoaPods to install TFTColor by adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!

target 'YourApp' do
    pod 'TFTColor'
end

Then, run the following command:

$ pod install

Manually

Swift

  1. Download and drop TFTColor.swift in your project.

Objective-C

  1. Download and drop TFTColor.h & TFTColor.m in your project.
  2. Congratulations!

Usage example

Swift

import TFTColor

// UIColor from RGB Hex String
UIColor(rgbHexString: "FF34AE", alpha: 1.0)
UIColor(rgbHexString: "#ea", alpha: 1.0)

// UIColor from RGB Hex Value
UIColor(rgbHexValue: 0xFF34AE alpha: 1.0)

// RGB Hex String from UIColor
let redColor = UIColor.redColor
redColor.rgbHexString //"FF0000"

// RGB Hex Value from UIColor
redColor.rgbHexValue //0xFF0000

// UIColor from CMYK component values 
// Creates and returns a color object using the specified opacity and CMYK component values.
// The components of the color object, specified as a value from 0.0 to 1.0.
UIColor(cyan:0.5, magenta: 0.5, yellow: 0.5, black: 0.5, alpha: 1.0)

// UIColor from CMYK Hex String
UIColor(cmykHexString: "FF34AE34", alpha:1.0)
UIColor(cmykHexString: "#ea", alpha:1.0)

// UIColor from CMYK Hex Value
UIColor(cmykHexValue: 0xFF34AE34 alpha:1.0)

// CMYK Hex String from UIColor
redColor.cmykHexString //"00646400"

// CMYK Hex Value from UIColor
redColor.cmykHexValue //0x00646400

Objective-C

// UIColor from RGB Hex String
[UIColor colorWithRGBHexString:@"FF34AE" alpha:1.0f];
[UIColor colorWithRGBHexString:@"#ea" alpha:1.0f];

// UIColor from RGB Hex Value
[UIColor colorWithRGBHexValue:0xFF34AE alpha:1.0f];
 
// RGB Hex String from UIColor
[UIColor rgbHexStringForColor:[UIColor redColor]]; //@"FF0000"
 
// RGB Hex Value from UIColor
[UIColor rgbHexValueForColor:[UIColor redColor]]; //0xFF0000

// UIColor from CMYK component values
// Creates and returns a color object using the specified opacity and CMYK component values.
// The components of the color object, specified as a value from 0.0 to 1.0.
[UIColor colorWithCyan:0.5f magenta:0.5 yellow:0.5f black:0.5f alpha:1.0f];

// UIColor from CMYK Hex String
[UIColor colorWithCMYKHexString:@"FF34AE34" alpha:1.0f];
[UIColor colorWithCMYKHexString:@"#EA" alpha:1.0f]; 

// UIColor from CMYK Hex Value
[UIColor colorWithCMYKHexValue:0xFF34AE34 alpha:1.0f];

// CMYK Hex String from UIColor
[UIColor cmykHexStringForColor:[UIColor redColor]]; //"00646400" 

// CMYK Hex Value from UIColor
[UIColor cmykHexValueForColor:[UIColor redColor]]; //0x00646400

Contribute

We would love for you to contribute to TFTColor, check the LICENSE file for more info.

Meta

Burhanuddin Sunelwala – @burhanuddin353[email protected]

Distributed under the The MIT License (MIT) license. See LICENSE for more information.

https://github.com/burhanuddin353/TFTColor

You might also like...
SheetyColors is an action sheet styled color picker for iOS
SheetyColors is an action sheet styled color picker for iOS

📱 Based on UIAlertController: The SheetyColors API is based on UIKit's UIAlertController. Simply add buttons to it as you would for any other Action Sheet by defining UIAlertAction instances. Therefore, it nicely integrates with the look & feel of all other native system dialogs. However, you can also chose to use the color picker it self without an action sheet.

A tool to calculate the color ratio of UIImage in iOS.
A tool to calculate the color ratio of UIImage in iOS.

UIImageColorRatio A tool to calculate the color ratio of UIImage in iOS. How to use UIImageColorRatio Get the color ratio of UIImage. let image = ...

Color framework for Swift & Objective-C (Gradient colors, hexcode support, colors from images & more).
Color framework for Swift & Objective-C (Gradient colors, hexcode support, colors from images & more).

Swift 3 To use the Swift 3 version, add this to your Podfile (until 2.2 or higher is released): pod 'ChameleonFramework/Swift', :git = 'https://githu

An attractive color generator for Swift. Ported from randomColor.js.
An attractive color generator for Swift. Ported from randomColor.js.

Random Color Swift Inspired by David Merfield's randomColor.js. It is a ported version to Swift. You can use the library to generate attractive random

Flat UI color palette helpers written in Swift.
Flat UI color palette helpers written in Swift.

FlatUIColors (swift) install Make sure you have the latest version of CocoaPods (gem install cocoapods) that has Swift support. At the time of this wr

Google Material Color Palette in Swift

Google Material Color in Swift Defined Google Material Color value ready to use in Swift refer to Google Material Design in Style/Color section ###How

A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.
A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.

Installation Drag the included Colours.h and Colours.m files into your project. They are located in the top-level directory. You can see a demo of how

Generate color based on the given string.
Generate color based on the given string.

PFColorHash Swift 4.0 SUPPORT! Generate color based on the given string. Thanks to color-hash. Usage Basic let colorHash = PFColorHash() // in HSL, H

A Lightweight But Powerful Color Kit (Swift)
A Lightweight But Powerful Color Kit (Swift)

BCColor A lightweight but powerful color kit (Swift) Features Pick Colors From Image Generate Monochrome Image Support Hex Color Style Lighten / Darke

Comments
  • Installation Section

    Installation Section

    Hey, your library is really interesting.

    The only problem I found was the README.md, which lacks an Installation Section I created this iOS Open source Readme Template so you can take a look on how to easily create an Installation Section If you want, I can help you to organize the lib.

    What are your thoughts? 😄

    opened by lfarah 1
Releases(1.0.1)
Owner
Burhanuddin Sunelwala
 iOS Developer
Burhanuddin Sunelwala
HEX color handling as an extension for UIColor

HEX color handling as an extension for UIColor. Written in Swift

Thi Doãn 692 Dec 22, 2022
Convenience methods for creating color using RGBA hex string.

UIColor+Hex, now Swift. Convenience method for creating autoreleased color using RGBA hex string.

R0CKSTAR 1.2k Dec 23, 2022
A UIColor extension with CSS3 Color names.

CSS3ColorsSwift Overview CSS3ColorsSwift provides a UIColor extension with Web Color names. Demo Run the demo project in the Demo directory without ca

WorldDownTown 67 Aug 6, 2022
HexColor is a simple extension that lets you initialize UIColors the way they were meant to be initialized: With hex integer values

HexColor is a simple extension that lets you initialize UIColors the way they were meant to be initialized: With hex integer values. Requirem

Tuomas Artman 103 Nov 24, 2022
System Color Picker - The macOS color picker as an app with more features

System Color Picker The macOS color picker as an app with more features Download Requires macOS 11 or later. Features Quickly copy, paste, and convert

Sindre Sorhus 758 Dec 24, 2022
ColorWheel Test - An attempt at creating a Color Wheel to be utilized for color picking in SwiftUI utlizing various tutuorials on youtube

This code focuses on creating a Color Wheel in which a user will be able to select a desired color to then be implemented in another project that will display that color in an LED connected to an arduino

Gerardo Cerpa 0 Jan 15, 2022
All wikipedia colors implemented as easy to use UIColor extension 🌈

UIColor-WikiColors All wikipedia colors implemented as an easy to use UIColor extension. Have you ever tried using UIColor.lightBlue just to be welcom

Szymon Maślanka 58 Jul 30, 2022
A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa.

iOS · macOS · watchOS · tvOS A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa. There is also support

Novem 3 Nov 20, 2022
UIGradient - A simple and powerful library for using gradient layer, image, color

UIGradient is now available on CocoaPods. Simply add the following to your project Podfile, and you'll be good to go.

Đinh Quang Hiếu 247 Dec 1, 2022
ChromaColorPicker - An intuitive HSB color picker built in Swift

An intuitive HSB color picker built in Swift. Supports multiple selection handles and is customizable to your needs.

Jonathan Cardasis 536 Dec 29, 2022