![](/style/images/good.png)
![](/style/images/bad.png)
GitHub - jathu/UIImageColors: Fetches the most dominant and prominent colors fro...
source link: https://github.com/jathu/UIImageColors
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
UIImageColors
iTunes style color fetcher for UIImage. It fetches the most dominant and prominent colors.
Installation
You can either directly copy UIImageColors.swift into your project or you can use CocoaPods: 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
UIImage Methods
getColors() -> UIImageColors
getColors(quality: UIImageColorsQuality) -> UIImageColors
getColors(_ completion: (UIImageColors) -> Void) -> Void
getColors(quality: UIImageColorsQuality, _ completion: (UIImageColors) -> Void) -> Void
UIImageColors Objects
UIImageColors
is struct that contains four different UIColor
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK