Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/PerfectFreeze/PFColorHash
Generate color based on the given string.
https://github.com/PerfectFreeze/PFColorHash
Last synced: 3 months ago
JSON representation
Generate color based on the given string.
- Host: GitHub
- URL: https://github.com/PerfectFreeze/PFColorHash
- Owner: PerfectFreeze
- License: mit
- Created: 2015-08-20T14:45:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-26T16:08:56.000Z (over 1 year ago)
- Last Synced: 2024-07-28T09:22:43.361Z (3 months ago)
- Language: Swift
- Homepage:
- Size: 359 KB
- Stars: 27
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - PFColorHash - Generate color based on the given string. (Color / Linter)
- awesome-ios-star - PFColorHash - Generate color based on the given string. (Color / Linter)
- fucking-awesome-ios - PFColorHash - Generate color based on the given string. (Color / Linter)
- fucking-awesome-ios - PFColorHash - Generate color based on the given string. (Color / Linter)
README
# PFColorHash
[![Cocoapods](https://cocoapod-badges.herokuapp.com/v/PFColorHash/badge.png)](http://cocoapods.org/?q=PFColorHash)
**Swift 4.0 SUPPORT!**
Generate color based on the given string. Thanks to [color-hash](https://github.com/zenozeng/color-hash).
![Sample](Sample.gif)
## Usage
### Basic
```Swift
let colorHash = PFColorHash()// in HSL, Hue ∈ [0, 360), Saturation ∈ [0, 1], Lightness ∈ [0, 1]
colorHash.hsl('Hello World') // [ 225, 0.65, 0.35 ]// in RGB, R, G, B ∈ [0, 255]
colorHash.rgb('Hello World') // [ 134, 150, 196 ]// in HEX
colorHash.hex('Hello World') // '#8696c4'
```### Custom Hash Function / Lightness / Saturation
```Swift
let colorHash = PFColorHash(hash: { (str: String) -> Int64 in
var hashValue: Int64 = 0
// Your Hash Function Here
return hashValue
})
``````Swift
let colorHash = PFColorHash(lightness: [0.35, 0.5, 0.65])
``````Swift
let colorHash = PFColorHash(saturation: [0.35, 0.5, 0.65])
``````Swift
let colorHash = PFColorHash(lightness: [0.35, 0.5, 0.65], saturation: [0.35, 0.5, 0.65])
```## License
Released under the MIT License.