NSString *html = @"<bold>Hello</bold> Now<br> <em>iOS</em> can create <h2>NSAttributedString</h2> from <br>HTMLs!"; NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSAttributedString *attrString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:nil]; CATextLayer *textLayer = [CATextLayer layer]; textLayer.backgroundColor = [UIColor redColor].CGColor; textLayer.string = attrString; textLayer.frame = CGRectMake(10, 60, 300, 400); [self.view.layer addSublayer:textLayer];
挺方便啊