https://github.com/mRs-/HexColors
HexColors is an extension for UIColor and NSColor to support for creating colors from a hex strings
https://github.com/mRs-/HexColors
extension hex hex-strings ios macos nscolor swift uicolor
Last synced: about 1 year ago
JSON representation
HexColors is an extension for UIColor and NSColor to support for creating colors from a hex strings
- Host: GitHub
- URL: https://github.com/mRs-/HexColors
- Owner: mRs-
- License: mit
- Created: 2012-12-02T20:10:04.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2022-09-01T16:09:00.000Z (over 3 years ago)
- Last Synced: 2024-10-29T12:42:53.425Z (over 1 year ago)
- Topics: extension, hex, hex-strings, ios, macos, nscolor, swift, uicolor
- Language: Swift
- Homepage:
- Size: 176 KB
- Stars: 457
- Watchers: 20
- Forks: 102
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[](https://github.com/mrs-/HexColors)
[](https://developer.apple.com/xcode)
[](https://swift.org)


[](https://travis-ci.org/mrs-/HexColors)
[](https://codecov.io/gh/mRs-/HexColors)
HexColors is an extension for UIColor and NSColor to support for creating colors from a hex string like #FF0088 or 8844FF and back to a String. Completely rewritten in Swift 3!
If you want to use this in Objective-C jump to the 4.X version tag.
If you want to use this in Swift < 3.2 use the 5.X version tag.
# RELEASE 6.0.0
Swift 4.0 compatiblity
# Examples
How to use HexColors in the different systems.
## iOS / watchOS / tvOS
### Generating UIColors
``` swift
let colorWithHex = UIColor("#ff8942")
let colorWithoutHex = UIColor("ff8942")
let colorWithHexAndAlhpa = UIColor("#ff8942DF")
let colorWithoutHexAndAlhpa = UIColor("ff8942DF")
let shortColorWithHex = UIColor("#fff")
let shortColorWithoutHex = UIColor("fff")
let shortColorWithHexAndAlpha = UIColor("#FFFD")
let shortColorWithoutHexAndAlpha = UIColor("#FFFD")
```
### Generating Hex Strings from UIColor
``` swift
let colorWithHex = UIColor("#ff8942")
let stringFromColor = colorWithHex.hex
```
## macOS
### Generating NSColor
``` swift
let colorWithHex = NSColor("#ff8942")
let colorWithoutHex = NSColor("ff8942")
let colorWithHexAndAlhpa = NSColor("#ff8942DF")
let colorWithoutHexAndAlhpa = NSColor("ff8942DF")
let shortColorWithHex = NSColor("#fff")
let shortColorWithoutHex = NSColor("fff")
let shortColorWithHexAndAlpha = NSColor("#FFFD")
let shortColorWithoutHexAndAlpha = NSColor("#FFFD")
```
### Generating Hex Strings from NSColor
``` swift
let colorWithHex = NSColor("#ff8942")
let stringFromColor = colorWithHex.hex
```
# Installation
## Requirements
HexColors requires **>= iOS 8.0** and **>=macOS 10.9**.
## Cocoapods
Add HexColors to your Podfile:
``` ruby
pod 'HexColors'
```
* `pod install HexColors`
## Carthage
Add HexColors to your Cartfile:
```
github "mRs-/HexColors"
```
## Swift Package Manager
To work with the Swift Package Manager you need to add a Package.swift file and defining your package.
``` swift
import PackageDescription
let package = Package(
name: "YourPackageName",
dependencies: [
.Package(url: "https://github.com/mRs-/HexColors", majorVersion: 5),
]
)
```
Then execute the Swift Package Manager with the following Shell commands:
``` bash
swift build
.build/debug/YourPackageName
```
## Manual
Simply just drag and drop the HexColors.swift in your project.
# Credits
HexColors was created by [Marius Landwehr](https://github.com/mRs-) because of the pain to create Colors from a API (mostly hex) converting to a UI/NSColor.
# Creator
[Marius Landwehr](https://github.com/mRs-) [@mariusLAN](https://twitter.com/mariusLAN)
# License
HexColors is available under the MIT license. See the LICENSE file for more info.