https://github.com/jonyfang/ffcolorswift
A lightweight color extension written in Swift.
https://github.com/jonyfang/ffcolorswift
Last synced: 10 months ago
JSON representation
A lightweight color extension written in Swift.
- Host: GitHub
- URL: https://github.com/jonyfang/ffcolorswift
- Owner: JonyFang
- License: mit
- Created: 2019-01-11T08:17:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-19T07:04:41.000Z (about 7 years ago)
- Last Synced: 2025-06-01T09:32:11.146Z (about 1 year ago)
- Language: Swift
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FFColorSwift
A lightweight color extension write in Swift.
## Requirements
- iOS 8.0+ / macOS 10.13.6+
- Xcode 10.1 (10B61) +
## Installation
### CocoaPods
[CocoaPods](http://cocoapods.org/) is a dependency manager, which automates and simplifies the process of using 3rd-party libraries like FFColorSwift in your projects. First, add the following line to your [Podfile](http://guides.cocoapods.org/using/using-cocoapods.html):
```
pod 'FFColorSwift'
```
### Carthage
To integrate `FFColorSwift` into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your `Cartfile`:
```
github "JonyFang/FFColorSwift"
```
### Manually
You can also integrate `FFColorSwift` directly with souce code. Clone the repo and copy `FFColorSwift.swift` to your project.
## Usage
### Initialize with Hex String
```swift
Color("000")
Color("000C")
Color("0x4DA2D9")
Color(hexString: "#4DA2D9")
Color(hexString: "#4DA2D9CC")
Color(hexString: "#4DA2D9", alpha: 0.8)
"#4DA2D9CC".color
```
### Initialize with Hex Int
```swift
Color(hexInt: 0x4DA2D9)
Color(hexInt: 0x4DA2D9, alpha: 0.8)
(0x4DA2D9).color
```
### Initialize with RGBA
```swift
Color(byteRed: 77, green: 162, blue: 217, alpha: 0.8)
```
### Get/Change Color Components
```swift
let color = Color(hexString: "#4DA2D9CC")
// Get color components
var (r, g, b, a) = color.colorComponents()
// Change color components
var red = "000".color.red(255)
var alphaColor = Color(hexInt: 0x4DA2D9).alpha(0.8)
```
### Convert to image
```swift
let image = "000".color.toImage()
```
## License
FFColorSwift is available under the MIT license. See the [LICENSE](./LICENSE) file for more info.