Skip to content

Instantly share code, notes, and snippets.

@johncodeos
johncodeos / hexStringToUIColor.swift
Last active May 30, 2019
hexStringToUIColor function . e.g var color1 = hexStringToUIColor("#d3d3d3")
View hexStringToUIColor.swift
func hexStringToUIColor (hex:String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet() as NSCharacterSet).uppercaseString
if (cString.hasPrefix("#")) {
cString = cString.substringFromIndex(cString.startIndex.advancedBy(1))
}
if ((cString.characters.count) != 6) {
return UIColor.grayColor()
}
@johncodeos
johncodeos / htmltagsinswift.swift
Created May 1, 2016
use HTML tags in uitextview
View htmltagsinswift.swift
extension NSData {
var attributedString: NSAttributedString? {
do {
return try NSAttributedString(data: self, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding], documentAttributes: nil)
} catch let error as NSError {
print(error.localizedDescription)
}
return nil
}
}
You can’t perform that action at this time.