Skip to content

luizdias/UIImageColors

 
 

Repository files navigation

UIImageColors

iTunes style color fetcher for UIImage. This is an almost identical port of Panic's OS X ColorArt for iOS Swift.

In other words, it fetches the most dominant and prominent colors.

preview

Example

Asynchronous example:

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

image.getColors { colors in
  backgroundView.backgroundColor = colors.backgroundColor
  mainLabel.textColor = colors.primaryColor
  secondaryLabel.textColor = colors.secondaryColor
  detailLabel.textColor = colors.detailColor
}

Synchronous example:

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

backgroundView.backgroundColor = colors.backgroundColor
mainLabel.textColor = colors.primaryColor
secondaryLabel.textColor = colors.secondaryColor
detailLabel.textColor = colors.detailColor

UIImage Methods

getColors() -> UIImageColors

Returns a UIImageColors object. The sample image is rescaled to a width of 250px and the aspect ratio height. This blocks the main thread.

getColors(scaleDownSize: CGSize) -> UIImageColors

Returns a UIImageColors object with a custom image rescale. Use smaller sizes for better performance at the cost of quality colors. Use larger sizes for better color sampling and quality at the cost of performance. This blocks the main thread.

getColors(completionHandler: (UIImageColors) -> Void) -> Void

Passes a UIImageColors object into the closure. The sample image is rescaled to a width of 250px and the aspect ratio height. This runs on the background thread.

getColors(scaleDownSize: CGSize, completionHandler: (UIImageColors) -> Void) -> Void

Passes a UIImageColors object into the closure, with a custom image rescale. Use smaller sizes for better performance at the cost of quality colors. Use larger sizes for better color sampling and quality at the cost of performance. This runs on the background thread.

UIImageColors

UIImageColors is struct that contains four different UIColors.

var backgroundColor
var primaryColor
var secondaryColor
var detailColor

License

The license is provided in the project folder. Please also refer to Panic's original license.


June 2015 - Toronto

About

iTunes style color fetcher for UIImage.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 98.2%
  • Ruby 1.8%