Skip to content
Fetches the most dominant and prominent colors from an image.
Branch: master
Clone or download
jathu Merge pull request #70 from cruisediary/master
Fix manual 'UIImageColors.swift' link broken'
Latest commit 9f8d0c8 May 6, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
NSImageColors Bump framework versions Jan 20, 2019
UIImageColors.xcodeproj Remove macOS example project Jan 27, 2019
UIImageColors Switch back to UIImageColors and UIImageColorsQuality Feb 3, 2019
UIImageColorsExample
.gitignore Migrate to Xcode project Oct 10, 2016
.swift-version Update podspec file and support swift 3 Sep 16, 2016
LICENSE Include MIT LICENSE. Mar 29, 2016
Package.swift Add support for Swift Package Manager Oct 10, 2016
README.md Fix manual 'UIImageColors.swift' link broken' May 4, 2019
UIImageColors.podspec fix mac deployment target Feb 10, 2019
preview.png Remove macOS example project screenshot Jan 28, 2019

README.md

platform: iOS, tvOS and macOS

UIImageColors

iTunes style color fetcher for UIImage and NSImage. It fetches the most dominant and prominent colors.

preview

Installation

Manual

Copy UIImageColors.swift into your project.

Cocoapods

Add UIImageColors to your Podfile:

pod 'UIImageColors'

Carthage

Add UIImageColors to your Cartfile:

github "jathu/UIImageColors"

Example

Asynchronous example:

let image = UIImage(named: "yeezus.png")

image.getColors { colors in
  backgroundView.backgroundColor = colors.background
  mainLabel.textColor = colors.primary
  secondaryLabel.textColor = colors.secondary
  detailLabel.textColor = colors.detail
}

Synchronous example:

let colors = UIImage(named: "yeezus.png").getColors()

backgroundView.backgroundColor = colors.background
mainLabel.textColor = colors.primary
secondaryLabel.textColor = colors.secondary
detailLabel.textColor = colors.detail

Image Methods

getColors() -> UIImageColors?
getColors(quality: ImageColorsQuality) -> UIImageColors?
getColors(_ completion: (UIImageColors?) -> Void) -> Void
getColors(quality: UIImageColorsQuality, _ completion: (UIImageColors?) -> Void) -> Void

UIImageColors Objects

UIImageColors is struct that contains four different UIColor (or NSColor on macOS) variables.

public struct UIImageColors {
    public var background: UIColor!
    public var primary: UIColor!
    public var secondary: UIColor!
    public var detail: UIColor!
}

UIImageColorsQuality is a enum with four different qualities. The qualities refer to how much the original image is scaled down. Lowest implies smaller size and faster performance at the cost of quality colors. High implies larger size with slower performance with good colors. Highest implies no downscaling and very good colors, but it is very slow.

The default is set to high.

public enum UIImageColorsQuality: CGFloat {
    case lowest = 50 // 50px
    case low = 100 // 100px
    case high = 250 // 250px
    case highest = 0 // No scale
}

License

The license is provided in the project folder. This is based on Panic's OS X ColorArt.


June 2015 - Toronto

You can’t perform that action at this time.