Skip to content

Instantly share code, notes, and snippets.

@ahmetgeymen
Last active November 30, 2017 07:34
Show Gist options
  • Save ahmetgeymen/c2e665dbf718e014e0c754f43bd4aab9 to your computer and use it in GitHub Desktop.
Save ahmetgeymen/c2e665dbf718e014e0c754f43bd4aab9 to your computer and use it in GitHub Desktop.
UIColor initialise with hexadecimal string like "#ABCDEF"
import UIKit
extension UIColor {
convenience init(hexaString: String, alpha: CGFloat = 1) {
let chars = Array(hexaString)
self.init(red: CGFloat(strtoul(String(chars[1...2]), nil, 16))/255,
green: CGFloat(strtoul(String(chars[3...4]), nil, 16))/255,
blue: CGFloat(strtoul(String(chars[5...6]), nil, 16))/255,
alpha: alpha)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment