Last active
November 30, 2017 07:34
-
-
Save ahmetgeymen/c2e665dbf718e014e0c754f43bd4aab9 to your computer and use it in GitHub Desktop.
UIColor initialise with hexadecimal string like "#ABCDEF"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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