UIColor+Hex,现在是 Swift 版本。

Build Status codecov.io Carthage compatible

使用 RGBA 十六进制字符串创建自动释放颜色的便捷方法。

    // Solid color
    let strokeColor = UIColor("#FFCC00").cgColor

    // Color with alpha
    let fillColor = UIColor("#FFCC00DD").cgColor

    // Supports shorthand 3 character representation
    let backgroundColor = UIColor("#FFF")

    // Supports shorthand 4 character representation (with alpha)
    let menuTextColor = UIColor("#013E")

    // "#FF0000FF"
    let hexString = UIColor.red.hexString()

    // Convert shorthand 4 character representation (with alpha) from argb to rgba
    if let rgba = "#AFFF".argb2rgba {
        let androidBackgroundColor = UIColor(rgba)
    }

    // Convert 8 character representation (with alpha) from argb to rgba
    if let rgba = "#AAFFFFFF".argb2rgba {
        let androidFrontColor = UIColor(rgba)
    }

发布说明

安装

Swift Package Manager

要将软件包依赖项添加到您的 Xcode 项目中,请选择 “File” > “Swift Packages” > “Add Package Dependency”,然后在文本字段中输入 https://github.com/yeahdongcn/UIColor-Hex-Swift

CocoaPods

只需将以下行添加到您的 Podfile

# required by CocoaPods 0.36.0.rc.1 for Swift Pods
use_frameworks!

pod 'UIColor_Hex_Swift', '~> 5.1.9'

然后在您使用它的地方导入它

import UIColor_Hex_Swift

(需要 CocoaPods v0.36 或更高版本。有关详细信息,请参阅 此博客文章。)

Carthage

只需将以下行添加到您的 Cartfile

github "yeahdongcn/UIColor-Hex-Swift" >= 5.1.9

然后将 HexColor.framework 添加到 Xcode 项目中的框架列表。

然后在您使用它的地方导入它

import HEXColor

更多信息请参阅 RSBarcodes_Swiftobjc 版本