Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yeahdongcn/UIColor-Hex-Swift

Convenience methods for creating color using RGBA hex string.
https://github.com/yeahdongcn/UIColor-Hex-Swift

Last synced: 4 days ago
JSON representation

Convenience methods for creating color using RGBA hex string.

Awesome Lists containing this project

README

        



UIColor+Hex, now Swift.

[![Build Status](https://travis-ci.org/yeahdongcn/UIColor-Hex-Swift.svg?branch=master)](https://travis-ci.org/yeahdongcn/UIColor-Hex-Swift) [![codecov.io](https://codecov.io/gh/yeahdongcn/UIColor-Hex-Swift/branch/master/graphs/badge.svg)](https://codecov.io/gh/yeahdongcn/UIColor-Hex-Swift/branch/master) ![](https://img.shields.io/badge/Swift-5.0-blue.svg?style=flat) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)
=================
Convenience method for creating autoreleased color using RGBA hex string.

```swift
// 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.

## Installation

### [Swift Package Manager](https://github.com/apple/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.

### [CocoaPods](http://cocoapods.org)

Simply add the following lines to your `Podfile`:
```ruby
# required by CocoaPods 0.36.0.rc.1 for Swift Pods
use_frameworks!

pod 'UIColor_Hex_Swift', '~> 5.1.9'
```

Then import it where you use it:
```swift
import UIColor_Hex_Swift
```

*(CocoaPods v0.36 or later required. See [this blog post](http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/) for details.)*

### [Carthage](http://github.com/Carthage/Carthage)

Simply add the following line to your `Cartfile`:

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

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

Then import it where you use it:
```swift
import HEXColor
```

---

See more in [RSBarcodes_Swift](https://github.com/yeahdongcn/RSBarcodes_Swift) and [objc version](https://github.com/yeahdongcn/RSBarcodes)