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: 3 months ago
JSON representation
Convenience methods for creating color using RGBA hex string.
- Host: GitHub
- URL: https://github.com/yeahdongcn/UIColor-Hex-Swift
- Owner: yeahdongcn
- License: mit
- Created: 2014-06-13T05:34:37.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-11-22T08:30:10.000Z (almost 2 years ago)
- Last Synced: 2025-07-31T09:35:34.965Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 183 KB
- Stars: 1,246
- Watchers: 19
- Forks: 143
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - UIColor-Hex-Swift - Convenience method for creating autoreleased color using RGBA hex string. (Color / Linter)
- awesome-swift - UIColor-Hex-Swift - Hex to UIColor converter. (Libs / Colors)
- awesome-swift - UIColor-Hex-Swift - Hex to UIColor converter. (Libs / Colors)
- awesome-ios - UIColor-Hex-Swift
- fucking-awesome-swift - UIColor-Hex-Swift - Hex to UIColor converter. (Libs / Colors)
- awesome-ios-star - UIColor-Hex-Swift - Convenience method for creating autoreleased color using RGBA hex string. (Color / Linter)
- awesome-swift-cn - UIColor-Hex-Swift - Hex to UIColor converter. (Libs / Colors)
- awesome-ios-cn - 官网
- fucking-awesome-ios - UIColor-Hex-Swift - Convenience method for creating autoreleased color using RGBA hex string. (Color / Linter)
- fucking-awesome-ios - UIColor-Hex-Swift - Convenience method for creating autoreleased color using RGBA hex string. (Color / Linter)
- awesome-swift - UIColor-Hex-Swift - Convenience methods for creating color using RGBA hex string. ` 📝 9 months ago ` (Colors [🔝](#readme))
README
UIColor+Hex, now Swift.
[](https://travis-ci.org/yeahdongcn/UIColor-Hex-Swift) [](https://codecov.io/gh/yeahdongcn/UIColor-Hex-Swift/branch/master)  [](https://github.com/Carthage/Carthage) 
=================
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)