SwiftColors 0.3.5

SwiftColors 0.3.5

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最后发布时间2015年12月
SPM支持SPM

Thi Doan维护。



  • 作者:
  • Doan Truong Thi

作为一个 UIColor 的扩展处理 HEX 颜色。用 Swift 编写。

示例

iOS

// With hash
let color: UIColor = UIColor(hexString: "#ff8942")

// Without hash, with alpha
let secondColor: UIColor = UIColor(hexString: "ff8942", alpha: 0.5)

// Short handling
let shortColorWithHex: UIColor = UIColor(hexString: "fff")

对于不想输入双引号的人来说,您可以从真实的十六进制值(一个 Int)初始化一个颜色

// With hash
let color: UIColor = UIColor(hex: 0xff8942)

// Without hash, with alpha
let secondColor: UIColor = UIColor(hex: 0xff8942, alpha: 0.5)

OSX

// With hash
let color: NSColor = NSColor(hexString: "#ff8942")

// Without hash, with alpha
let secondColor: NSColor = NSColor(hexString: "ff8942", alpha: 0.5)

// Short handling
let shortColorWithHex: NSColor = NSColor(hexString: "fff")

// From a real hex value (an `Int`)
// With hash
let color: NSColor = NSColor(hex: 0xff8942)

// Without hash, with alpha
let secondColor: NSColor = NSColor(hex: 0xff8942, alpha: 0.5)

安装

手动

  • SwiftColors.swift 文件拖放到您的项目中

需求

iOS 8.0 或更高版本。

许可协议

MIT