Last active
May 23, 2016 07:25
-
-
Save gkye/1a9dd49e09a9f141adae01c405265093 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
extension String { | |
//Convert html strings to an attributed string | |
var html2AttributedString: NSMutableAttributedString? { | |
guard | |
let data = dataUsingEncoding(NSUTF8StringEncoding) | |
else { return nil } | |
do { | |
let attrStr = try NSMutableAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute:NSUTF8StringEncoding], documentAttributes: nil) | |
attrStr.addAttributes([NSFontAttributeName: UIFont.systemFontOfSize(17.0)], range: NSRange(location: 0, length: attrStr.length)) | |
return attrStr | |
} catch let error as NSError { | |
print(error.localizedDescription) | |
return nil | |
} | |
} | |
var html2String: String { | |
return html2AttributedString?.string ?? "" | |
} | |
} | |
extension UIViewController{ | |
//Add acitivityView in center of view | |
func addLoader(activity_view: UIActivityIndicatorView){ | |
activity_view.frame = CGRectMake(0.0, 0.0, 40.0,40.0) | |
activity_view.center = self.view.center | |
self.view.addSubview(activity_view) | |
activity_view.startAnimating() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment