UIImageColors

Fetches the most dominant and prominent colors from an image.

Github星跟蹤圖

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

主要指標

概覽
名稱與所有者jathu/UIImageColors
主編程語言Swift
編程語言Swift (語言數: 3)
平台
許可證MIT License
所有者活动
創建於2015-06-19 08:00:52
推送於2021-12-14 14:24:39
最后一次提交2021-05-01 22:16:09
發布數16
最新版本名稱2.2.0 (發布於 )
第一版名稱1.0.0 (發布於 )
用户参与
星數3.3k
關注者數44
派生數247
提交數127
已啟用問題?
問題數0
打開的問題數0
拉請求數31
打開的拉請求數0
關閉的拉請求數10
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?