Swiftpack.co - yeahdongcn/UIColor-Hex-Swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Convenience methods for creating color using RGBA hex string.
.package(url: "https://github.com/yeahdongcn/UIColor-Hex-Swift.git", from: "5.1.7")

UIColor+Hex, now Swift. Build Status codecov.io Carthage compatible

Convenience method for creating autoreleased color using RGBA hex string.

    // 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)

Release Notes

  • Upgrade to Swift 5.
  • macOS gets supported.


Swift Package Manager

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter https://github.com/yeahdongcn/UIColor-Hex-Swift to the text field.


Simply add the following lines to your Podfile:

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

pod 'UIColor_Hex_Swift', '~> 5.1.7'

Then import it where you use it:

import UIColor_Hex_Swift

(CocoaPods v0.36 or later required. See this blog post for details.)


Simply add the following line to your Cartfile:

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

Then add the HexColor.framework to your frameworks list in the Xcode project.

Then import it where you use it:

import HEXColor

See more in RSBarcodes_Swift and objc version


Stars: 1078
Last commit: 2 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Swift 4.2
3 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics