Felucia 1.5.3

Felucia 1.5.3

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最新发布2016年11月
SwiftSwift 版本3.0
SPM支持 SPM

Michał Tynior 维护。



Felucia 1.5.3

Felucia 为 UIColor 提供了有用的扩展。

要求

  • iOS 9.0+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8+

集成

Swift 包管理器 (SPM)

你可以使用 Swift 包管理器 通过将其添加到 Package.swift 文件中来安装 Felucia

import PackageDescription

let package = Package(
    name: "MyApp",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/mtynior/Felucia.git", majorVersion: 1)
    ]
)

手动

你也可以手动将 Felucia 添加到你的项目中

  1. 下载 Felucia.swift 文件,
  2. Felucia.swift 拖到你的项目树中。

使用

颜色初始化

Hex ARGB 字符串

UIColor(hexARGB: "#fff")
UIColor(hexARGB: "fff")
UIColor(hexARGB: "#e2f5d3")
UIColor(hexARGB: "e2f5d3")
UIColor(hexARGB: "#ffe2f5d3")
UIColor(hexARGB: "ffe2f5d3")

RGBA

UIColor(r: 255, g: 128, b: 64, a: 255)
UIColor(r: 255, g: 128, b: 64)

UIColor(red: 1.0, green: 0.5, blue: 0.25, alpha: 1.0)
UIColor(red: 1.0, green: 0.5, blue: 0.25)

CMYK

UIColor(cyan: 0, magneta: 0.5, yellow: 0.75, black: 0.498)

HSLA

h 可以设置为 [0, 1] 或 [0, 360] 范围内的值。

s 可以设置为在 l 为 [0, 1] 或 [0, 100] 范围内的值。

a 可以设置为 [0, 1] 范围内的值。

UIColor(h: 157.0, s: 24, l: 51)
UIColor(h: 0.436, s: 0.24, l: 0.51)
UIColor(h: 0.436, s: 0.24, l: 0.51, a: 1.0)

检索颜色成分

UIColor(r: 255, g: 128, b: 64, a: 255).rgba() // (r: 255, g: 128, b: 64, a: 255)
UIColor(r: 255, g: 128, b: 64, a: 255).rgbaArray() // [255, 128, 64, 255]

UIColor(r: 255, g: 128, b: 64, a: 255).rgbaf() // (r: 1.0, g: 0.5, b: 0.25, a: 1.0)
UIColor(r: 255, g: 128, b: 64, a: 255).rgbafArray() // [1.0, 0.5, 0.25, 1.0]

UIColor(r: 255, g: 128, b: 64, a: 255).hsba() // (h: 0.056, s: 0.749, b: 1.0, a: 1.0)
UIColor(r: 255, g: 128, b: 64, a: 255).hsbaArray() // [0.056, 0.749, 1.0, 1.0]

UIColor(r: 255, g: 128, b: 64, a: 255).hsla() // (h: 0.0558464, s: 1.0, l: 0.62549, a: 1.0)
UIColor(r: 255, g: 128, b: 64, a: 255).hslaArray() // [0.0558464, 1.0, 0.62549, a:1.0]

UIColor(r: 255, g: 128, b: 64, a: 255).cmyk() // (c: 0.0, m: 0.498, y: 0.749, k: 0.0)
UIColor(r: 255, g: 128, b: 64, a: 255).cmykArray() // [0.0, 0.498, 0.749, 0.0]

工具

互补色

返回互补色。

let color = UIColor.whiteColor().complementaryColor() 
color.rgba() // (r: 0, g: 0, b: 0, a: 255)

变亮

将颜色变亮给定量,从 0.0 到 1.0。提供 1.0 总是返回白色。

let color = UIColor.redColor().lighten()
color.rgba() // (r: 255, g: 51, b: 51, a: 255)
let color = UIColor.redColor().lighten(1.0)
color.rgba() // (r: 255, g: 255, b: 255, a: 255)

变暗

将颜色变暗给定量,从 0.0 到 1.0。提供 1.0 总是返回黑色。

let color = UIColor.redColor().darken()
color.rgba() // (r: 204, g: 0, b: 0, a: 255)
let color = UIColor.redColor().darken(1.0)
color.rgba() // (r: 0, g: 0, b: 0, a: 255)

灰度化

将颜色变为灰度。

let color = UIColor(r: 67, g: 122, b: 134).grayscale()
color.rgba() // (r: 106, g: 106, b: 106, a: 255)

IsLight

当颜色的感知亮度为浅时,返回 true

UIColor.whiteColor().isLight() // true

UIColor.blackColor().isLight() // false

IsDark

当颜色的感知亮度为深时,返回 true

UIColor.blackColor().isLight() // true

UIColor.whiteColor().isLight() // false

Random

返回一个随机颜色。

let color = UIColor.randomColor()
color.rgba() // (r: 67, g: 122, b: 134 a:255)

License

Felucia 在 MIT 许可下发布。有关详细信息,请参阅 LICENSE。