UIImageColors
用于 UIImage
和 NSImage
的iTunes风格颜色检索器。它检索最突出和最显眼的颜色。
安装
手动
将 UIImageColors.swift 复制到您的项目中。
Cocoapods
将 UIImageColors 添加到您的 Podfile
pod 'UIImageColors'
Carthage
将 UIImageColors
添加到您的 Cartfile
github "jathu/UIImageColors"
示例
异步示例
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
}
同步示例
let colors = UIImage(named: "yeezus.png").getColors()
backgroundView.backgroundColor = colors.background
mainLabel.textColor = colors.primary
secondaryLabel.textColor = colors.secondary
detailLabel.textColor = colors.detail
图片方法
getColors() -> UIImageColors?
getColors(quality: ImageColorsQuality) -> UIImageColors?
getColors(_ completion: (UIImageColors?) -> Void) -> Void
getColors(quality: UIImageColorsQuality, _ completion: (UIImageColors?) -> Void) -> Void
UIImageColors 对象
UIImageColors
是一个结构,它包含四个不同的 UIColor
(或 macOS 上的 NSColor
) 变量。
public struct UIImageColors {
public var background: UIColor!
public var primary: UIColor!
public var secondary: UIColor!
public var detail: UIColor!
}
UIImageColorsQuality
是一个包含四个不同质量的枚举类型。这些质量指的是原始图像被缩小多少。 最低
表示更小的尺寸和更快的性能,但颜色质量会降低。 最高
表示更大的尺寸、较慢的性能,但颜色质量很好。 最高
表示没有缩小,颜色非常好,但速度非常慢。
默认设置为 最高
。
public enum UIImageColorsQuality: CGFloat {
case lowest = 50 // 50px
case low = 100 // 100px
case high = 250 // 250px
case highest = 0 // No scale
}
许可证
许可证位于项目文件夹中。这是基于 Panic 的 OS X ColorArt。
2015 年 6 月 - 多伦多