Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import UIKit
- let attrStr = try NSMutableAttributedString(
- data: "<b>sdad </b> assdds.".dataUsingEncoding(NSUnicodeStringEncoding)!,
- options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType],
- documentAttributes: nil)
- let fontNormal = UIFont(name: "Helvetica", size: 15)!
- let fontBold = UIFont(name: "Helvetica-Bold", size: 15)!
- func styled(attrStr: NSAttributedString) -> NSAttributedString {
- let att = NSMutableAttributedString(attributedString: attrStr)
- let rangeAll = NSRange(location: 0, length: att.length)
- att.enumerateAttributesInRange(rangeAll, options: .LongestEffectiveRangeNotRequired) { attrs, range, stop in
- let font = attrs["NSFont"]!
- att.addAttribute(NSFontAttributeName, value: font.fontName.containsString("Bold") ? fontBold : fontNormal, range: range)
- }
- att.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: rangeAll)
- return att
- }
- let s = styled(attrStr)
- //let rangeAll = NSRange(location: 0, length: attrStr.length)
- //attrStr.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: rangeAll)
- //attrStr.addAttribute(NSFontAttributeName, value: UIFont(name: "Times New Roman", size: 18.0)!, range: rangeAll)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement