Swiftpack.co - Package - jathu/UIImageColors

Swift 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

Github

link
Stars: 2825

Dependencies

Used By

Total: 0

Releases

2.2.0 - 2019-12-05 06:28:18

2.1.0 - 2019-02-10 20:18:50

  • Support for macOS
  • Update to Swift 4.0

2.0.1 - 2018-08-05 05:45:45

  • Exposes a public initializer for UIImageColors

2.0.0 - 2018-01-06 08:09:18

  • 2x Performance Improvement
  • Refer to PR #54

1.4.0 - 2017-06-09 12:43:33

  • Rename struct variables

1.3.1 - 2017-05-11 22:07:47

  • Support for tvOS

1.3.0 - 2017-04-29 21:01:34

Refer to PR #50

1.2.1 - 2016-10-24 18:03:06

  • Fix podspec type

1.2.0 - 2016-10-10 12:41:58

  • Support for Carthage
  • Support for Swift Package Manager
  • Swift 3 CocoaPods fix

1.1.1 - 2016-09-16 13:34:57

  • Support for Swift 3

1.0.5 - 2016-06-09 16:16:41

  • Privatize all UIColor methods
  • Privatize UIImage resize method

1.0.4 - 2016-05-19 10:53:09

  • Added closures
  • Speed up compile time with faster isContrastingColor

1.0.3 - 2015-12-18 19:23:39

  • Remove C style for loops

1.0.2 - 2015-12-14 22:42:27

  • Fix memory leak issue: free malloc

1.0.1 - 2015-10-16 17:33:30

  • Support for Swift 2