TFTColor 1.0.2

TFTColor 1.0.2

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新版本2020年2月
SPM支持 SPM

Burhanuddin Sunelwala维护。



TFTColor 1.0.2

TFTColor

一个简单的UIColor库,可以从RGB十六进制字符串/值、CMYK十六进制字符串/值或CMYK基本成分值获取UIColor对象。您还可以检索RGB十六进制字符串/值和CMYK十六进制字符串/值。

Awesome iOS Swift Version Objective C License DOI Build Status

特性

  • 将RGB十六进制字符串/值转换为UIColor
  • 将CMYK十六进制字符串/值转换为UIColor
  • 从UIColor获取RGB十六进制字符串/值
  • 从UIColor获取CMYK十六进制字符串/值
  • 从基本成分初始化CMYK
  • 这个库的一个美好之处在于您可以输入带有 #0x0X 的hex值,它会相应处理。
  • 您还可以输入任何长度的hex值,这也会被处理。
  • 该库还处理非hex字符。

支持的RGB十六进制字符串格式

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

支持CMYK十六进制字符串格式

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

要求

  • iOS 8.0+
  • Xcode 7.3+

安装

CocoaPods

您可以使用 CocoaPods 来通过向您的 Podfile 中添加它安装 TFTColor

platform :ios, '9.0'
use_frameworks!

target 'YourApp' do
    pod 'TFTColor'
end

然后,运行以下命令

$ pod install

手动

Swift

  1. 下载并将 TFTColor.swift 放到您的项目中。

Objective-C

  1. 下载并将 TFTColor.hTFTColor.m 放到您的项目中。
  2. 恭喜!

用法示例

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

投稿

我们很乐意让您为 TFTColor 做出贡献,请查看 LICENSE 文件以获取更多信息。

元信息

Burhanuddin Sunelwala – @burhanuddin353[email protected]

基于 The MIT License (MIT) 协议分发。查看 LICENSE 文件以获取更多信息。

https://github.com/burhanuddin353/TFTColor