CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✗ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Dec 2014 |
Maintained by Wojtek Czekalski.
This repo consits of a few categories for dealing with HTML and NSAttributedStrings.
HEY! Apple provided me with methods for these tasks. Yes, unless you want to specify different attributes for, let's say, headers and paragraphs.
When iOS creates an attributed string from HTML NSHTMLParser also parses CSS attributes. Therefore if you add following CSS to your HTML
p {
font-name:"Helvetica";
font-size:14px;
}
h1 {
font-name:"Georgia";
font-size:16px;
}Your headers in NSAttributedString will have these attributes: @{NSFontAttributeName : [UIFont fontWithName:@"Georgia" size:16.f]}
whereas paragraphs will be attributed with:
@{NSFontAttributeName : [UIFont fontWithName:@"Helvetica" size:14.f]}
#import "NSAttributedString+HTMLStyle.h"
...
UITextView *textView;
NSData *htmlData;
textView.attributedText = [NSAttributedString attributedStringFromHTMLData:htmlData];
...Or with custom attributes...
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:17.f]} forHTMLAttribute:QRHTMLAttributeParagraph flatten:YES];
textView.attributedText = [NSAttributedString attributedStringFromHTMLData:htmlData attributes:attributes];Install via Cocoapods:
pod 'NSAttributedString-HTMLStyle'
or copy NSAttributedString+HTMLStyle.*
This repository was originally developed by Wojtek Czekalski during the developmment of Quickread.