You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HEX color handling as an extension for UIColor. Written in Swift.
Examples
iOS
// With hash
letcolor:UIColor=UIColor(hexString:"#ff8942")
// Without hash, with alpha
letsecondColor:UIColor=UIColor(hexString:"ff8942", alpha:0.5)
// Short handling
letshortColorWithHex:UIColor=UIColor(hexString:"fff")
For those who don't want to type the double quotation, you can init a color from a real hex value (an Int)
// With hash
letcolor:UIColor=UIColor(hex:0xff8942)
// Without hash, with alpha
letsecondColor:UIColor=UIColor(hex:0xff8942, alpha:0.5)
OSX
// With hash
letcolor:NSColor=NSColor(hexString:"#ff8942")
// Without hash, with alpha
letsecondColor:NSColor=NSColor(hexString:"ff8942", alpha:0.5)
// Short handling
letshortColorWithHex:NSColor=NSColor(hexString:"fff")
// From a real hex value (an `Int`)
// With hash
letcolor:NSColor=NSColor(hex:0xff8942)
// Without hash, with alpha
letsecondColor:NSColor=NSColor(hex:0xff8942, alpha:0.5)
Installation
Swift Package Manager
Add this as a dependency in your Package.swift:
import PackageDescription
letpackage=Package(
name:"MyPackage",
dependencies:[
// Other dependencies
.package(url:"https://github.com/thii/SwiftHEXColors.git", from:"1.3.1")])
CocoaPods
To integrate SwiftHEXColors into your Xcode project using CocoaPods, specify it in your Podfile: