Last active
May 10, 2017 06:26
-
-
Save abhimuralidharan/5e3a02428361a4d8ec7b8dc0a4357936 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // ___FILENAME___ | |
| // ___PROJECTNAME___ | |
| // | |
| // Created by ___FULLUSERNAME___ on ___DATE___. | |
| //___COPYRIGHT___ | |
| // | |
| /* | |
| DISCLAIMER | |
| The goal of GitHub's open source licensing efforts is to provide a starting point to help you make an informed choice. GitHub displays license information to help users get information about open source licenses and the projects that use them. We hope it helps, but please keep in mind that we’re not lawyers and that we make mistakes like everyone else. For that reason, GitHub provides the information on an “as-is” basis and makes no warranties regarding any information or licenses provided on or through it, and disclaims liability for damages resulting from using the license information. If you have any questions regarding the right license for your code or any other legal issues relating to it, it’s always best to consult with a professional. | |
| */ | |
| import Foundation | |
| import UIKit | |
| class ___FILEBASENAMEASIDENTIFIER___ { | |
| func colorFromHexString (_ hex:String) -> UIColor { | |
| var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased() | |
| if (cString.hasPrefix("#")) { | |
| cString.remove(at: cString.startIndex) | |
| } | |
| if ((cString.characters.count) != 6) { | |
| return UIColor.gray | |
| } | |
| var rgbValue:UInt32 = 0 | |
| Scanner(string: cString).scanHexInt32(&rgbValue) | |
| return UIColor( | |
| red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0, | |
| green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0, | |
| blue: CGFloat(rgbValue & 0x0000FF) / 255.0, | |
| alpha: CGFloat(1.0) | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment